summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-09-05 16:58:02 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-09-05 16:58:02 +0000
commit20f15720da7b9f6baca01d8bfef359263b671824 (patch)
treee84bb6ba7fa8f897f27a101df47a729ea4c706f6 /lib/sqlalchemy/attributes.py
parentf3d72a71871180f6b7ea8f7a09094d9e22aa84fd (diff)
downloadsqlalchemy-20f15720da7b9f6baca01d8bfef359263b671824.tar.gz
restored "optimistic" behavior of hasparent. its generally disastrous without that flag as its impossible to load all lazy loaders, deal with attributes that "noload", etc. just to check for orphan status.
Diffstat (limited to 'lib/sqlalchemy/attributes.py')
-rw-r--r--lib/sqlalchemy/attributes.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py
index b29b03aa8..af2c908c4 100644
--- a/lib/sqlalchemy/attributes.py
+++ b/lib/sqlalchemy/attributes.py
@@ -33,8 +33,14 @@ class InstrumentedAttribute(object):
def hasparent(self, item, optimistic=False):
"""return the boolean value of a "hasparent" flag attached to the given item.
+
+ the 'optimistic' flag determines what the default return value should be if
+ no "hasparent" flag can be located. as this function is used to determine if
+ an instance is an "orphan", instances that were loaded from storage should be assumed
+ to not be orphans, until a True/False value for this flag is set. an instance attribute
+ that is loaded by a callable function will also not have a "hasparent" flag.
"""
- return item._state.get(('hasparent', id(self)), False)
+ return item._state.get(('hasparent', id(self)), optimistic)
def sethasparent(self, item, value):
"""sets a boolean flag on the given item corresponding to whether or not it is
@@ -486,12 +492,16 @@ class CommittedState(object):
if value is not False:
if attr.uselist:
self.data[attr.key] = [x for x in value]
- if attr.trackparent:
- [attr.sethasparent(x, True) for x in self.data[attr.key] if x is not None]
+ # not tracking parent on lazy-loaded instances at the moment.
+ # its not needed since they will be "optimistically" tested
+ #if attr.trackparent:
+ # [attr.sethasparent(x, True) for x in self.data[attr.key] if x is not None]
else:
self.data[attr.key] = value
- if attr.trackparent and value is not None:
- attr.sethasparent(value, True)
+ # not tracking parent on lazy-loaded instances at the moment.
+ # its not needed since they will be "optimistically" tested
+ #if attr.trackparent and value is not None:
+ # attr.sethasparent(value, True)
def rollback(self, manager, obj):
for attr in manager.managed_attributes(obj.__class__):