- attached merge_PASSIVE_NO_RESULT.py
merge() fails for one to one relationships marked load_on_pending=True and delete_orphan
AttributeError: 'symbol' object has no attribute '_sa_instance_state'
# orm/unitofwork.py
def track_cascade_events(descriptor, prop):
"""Establish event listeners on object attributes which handle
cascade-on-set/append.
"""
...
...
...
def set_(state, newvalue, oldvalue, initiator):
# process "save_update" cascade rules for when an instance
# is attached to another instance
if oldvalue is newvalue:
return newvalue
sess = session._state_session(state)
if sess:
prop = state.manager.mapper._props[key](key)
if newvalue is not None:
newvalue_state = attributes.instance_state(newvalue)
if prop.cascade.save_update and \
(prop.cascade_backrefs or key == initiator.key) and \
not sess._contains_state(newvalue_state):
sess._save_or_update_state(newvalue_state)
if oldvalue is not None and prop.cascade.delete_orphan:
oldvalue_state = attributes.instance_state(oldvalue) # <=== oldvalue is PASSIVE_NO_RESULT
if oldvalue_state in sess._new and \
prop.mapper._is_orphan(oldvalue_state):
sess.expunge(oldvalue)
return newvalue
...
...
event.listen(descriptor, 'set', set_, raw=True, retval=True)
history from http://groups.google.com/group/sqlalchemy/browse_thread/thread/51b134cd70af6fe7
Comments (12)
-
Account Deleted -
Account Deleted - changed title to merge() fails for one to one relationships marked load_on_pending=True and delete_orphan
-
repo owner - changed milestone to 0.7.5
should be a quick fix there, thanks for the test.
-
Account Deleted hey, sorry for the nagging, but this is preventing us pushing code to several customers... is it a suitable patch to just change this:
if oldvalue is not None and prop.cascade.delete_orphan:
to this:
if oldvalue is not None and oldvalue is not attributes.PASSIVE_NO_RESULT and prop.cascade.delete_orphan:
Or am I missing something?
-
repo owner that's pretty much the change, then adding your test to the unit tests somewhere, yup
-
Account Deleted What about other attributes.PASSIVE<something> symbols? Is PASSIVE_NO_RESULT the only one we'd expect there?
-
repo owner NEVER_SET might or might not be something that can be returned, I see codepaths for that, though would be nice to come up with a test which hits it.
-
Account Deleted - attached 2374.kb.patch
patch with two tests
-
Account Deleted Both tests (essentially same test except one with None and one with object) fail before change is applied.
Could you let me know whether this should make it in (I'd like to patch my "branch" with what will eventually be in sync).
P.S. As it turns out, typing "
yum install hg
" was quite painless after all. ;) -
repo owner - changed status to resolved
45e6875752fcaf7d3a60907959ed9d154cca0d5d thanks again for the great patch !
-
Account Deleted Replying to zzzeek:
45e6875752fcaf7d3a60907959ed9d154cca0d5d thanks again for the great patch !
Very welcome. I'm pleased I can support the project in some way; you've been extraordinarily helpful on a continual basis for our project.
-
repo owner - removed milestone
Removing milestone: 0.7.5 (automated comment)
- Log in to comment
script that causes failure