python - SQLAlchemy DetachedInstanceError with regular attribute (not a relation) -
I have just started using SQLite and have received a separate instant error and can not find much information on this. Has pie. I am using an example out of a session, so it is natural that if SQLAlchemy is unable to load any relationship, if it is not loaded already, however, the entry I am entering is not related There is no connection to this object in fact. I was getting a solution like eager loading, but I can not apply it because it is not a relation. I tried to "touch" this feature before closing the session, but it still does not stop the exception. What can be the reason for this exception of non-relational property, even then it can be reached successfully once before? Any help in debugging this issue is appreciated. Meanwhile, I try to get a reputable stand-alone scenario and update it here.
Update: This is the actual exception message with some heaps:
file "/ home /hari/bin/lib/python2.6/site-packages/SQLAlchemy- 0.6.1-py2.6.egg / sqlalchemy / orm / attributes.py ", line 159, __get__ return to self.impl.get (instance_state (example), instance_dict (example)) file" / home / hari / bin / Lib / python2.6 / site-packages / SQLAlchemy-0.6.1-py2.6.egg / sqlalchemy / orm / attributes.py ", line 377, received value = callable_ (idle = inactive) file" / home / hari / Bin / lib / python2.6 / site-packages / SQLAlchemy-0.6.1-py2.6.egg / sqlalchemy / orm / state.py ", line 280, __call__ in self.manager.deferred_scalar_loader (self, toload) the file" /home/hari/bin/lib/python2.6/site-packages/SQLAlchemy-0.6.1-py2.6.egg/sqlalchemy/orm/mapper.py " , Line 2323, _load_scalar_attributes (in state_str (state)) Separate instant error: Example & lt; ReportingJob & gt; 0xa41cd8c Is not bound for a session; metadata = metadata () ModelBase = declarative_base (metadata = metadata) class ReportingJob (ModelBase: attribute refresh operation
partial model looks like this Can be increased): __tablename__ = 'reporting_job' job_id = column (BigInteger, sequence ('job_id_sequence'), primary_key = true) client_id = column (BigInteger, tap = true)
and area client_id
Question: What is causing this exception with the use of one of the following:
jobs = session \ .query (ReportingJob) \ .filter (ReportingJob .job_id == job_id) \. All () Job: #Fixem (Hari): Optional solution for lazy loading feature. Jobs [0] .client_id return jobs [0]
Session scope later triggers exception:
msg = msg + ", Client_id:% s "% job.client_id
I found the original reason when trying After the session was closed to reduce the cause of the code, I placed the same attribute access code at different places and found that this query is not the cause of any issue immediately after the session is closed. It turns out that the problem starts after the closure of the fresh session, which is opened to update the object. Once I understood that the position of the object was unusable after a session was closed, then I was able to find it, which was discussed on this issue. There are two solutions to exit the thread:
- Open the session (which is clear)
- Specify
expire_on_commit = false
tosession Manager ()
.
The session is to manually set expire_on_commit
to incorrect
, something like this: session.expire_on_commit = False
. I've verified that this resolves my problem.
I wanted to thank you for this good read!! I absolutely loved every bit of it. I have you book marked to check out new things you post…
ReplyDeleteKBC Lottery Winner 2020
KBC Lottery Winner 2020 List Today
KBC Lottery Winner 2020 25 Lakh List
KBC Lottery WinnerList 2020
KBC Lottery Winner 2019 25 Lakh List
KBC Lottery Number Check
KBC Lottery Number Check Online
Kaun Banega Crorepati Lottery Winner
"This was a well written blog.
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"