Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parent instance is not bound to a Session; lazy load operation of attribute ’account’ cannot proceed

While trying to do the following operation:

for line in blines:     line.account = get_customer(line.AccountCode) 

I am getting an error while trying to assign a value to line.account:

DetachedInstanceError: Parent instance <SunLedgerA at 0x16eda4d0> is not bound to a       Session; lazy load operation of attribute 'account' cannot proceed 

Am I doing something wrong??

like image 763
maruthi reddy Avatar asked Dec 20 '12 07:12

maruthi reddy


1 Answers

"detached" means you're dealing with an ORM object that is not associated with a Session. The Session is the gateway to the relational database, so anytime you refer to attributes on the mapped object, the ORM will sometimes need to go back to the database to get the current value of that attribute. In general, you should only work with "attached" objects - "detached" is a temporary state used for caching and for moving objects between sessions.

See Quickie Intro to Object States, then probably read the rest of that document too ;).

like image 169
zzzeek Avatar answered Sep 19 '22 23:09

zzzeek