[sqlalchemy] Re: association proxy error: stale association proxy
I understand why I'm seeing the error. But should the user really be required to keep the parent around in a variable? I would have thought that the session would be tracking each successive changes. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: association proxy error: stale association proxy
Paul K wrote: The following code duplicates a situation I'm seeing with the association proxy. There are at least two ways I can avoid having the error happen. But since I wasn't sure if the error is a usage error, I wanted to post here first before implementing my work around. One work around for the test code is to delete/comment out line 77 (commented as such). I understand why I'm seeing the error. But should the user really be required to keep the parent around in a variable? I would have thought that the session would be tracking each successive changes. This is fixed in the trunk @ r4593. The issue was in association proxy's handling of a stale cache attribute it stashes on instances and was fundamentally: p_copy = copy.copy(parent) del parent p_copy.kids.append(a_kid) # previously, boom That's similar to what was going under the orm hood with the modified instances coming in and out of scope in have_a_kid. The patch in the trunk is pretty small, but if that's not an option you can work around the issue somewhat painfully by removing the cache attribute from instances: for attr in dir(p_copy): if attr.startswith('_AssociationProxy_kid_associations_'): delattr(p_copy, attr) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: association proxy error: stale association proxy
Thanks. That fixed what I was seeing. Paul Kippes On Apr 29, 1:49 pm, jason kirtland [EMAIL PROTECTED] wrote: Paul K wrote: The following code duplicates a situation I'm seeing with the association proxy. There are at least two ways I can avoid having the error happen. But since I wasn't sure if the error is a usage error, I wanted to post here first before implementing my work around. One work around for the test code is to delete/comment out line 77 (commented as such). I understand why I'm seeing the error. But should the user really be required to keep the parent around in a variable? I would have thought that the session would be tracking each successive changes. This is fixed in the trunk @ r4593. The issue was in association proxy's handling of a stale cache attribute it stashes on instances and was fundamentally: p_copy = copy.copy(parent) del parent p_copy.kids.append(a_kid) # previously, boom That's similar to what was going under the orm hood with the modified instances coming in and out of scope in have_a_kid. The patch in the trunk is pretty small, but if that's not an option you can work around the issue somewhat painfully by removing the cache attribute from instances: for attr in dir(p_copy): if attr.startswith('_AssociationProxy_kid_associations_'): delattr(p_copy, attr) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---