diff options
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r-- | lib/sqlalchemy/orm/state.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 2b43d2cac..9ee31bff8 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -43,6 +43,10 @@ class InstanceState(object): @util.memoized_property def callables(self): return {} + + @property + def has_identity(self): + return bool(self.key) def detach(self): if self.session_id: @@ -219,6 +223,14 @@ class InstanceState(object): If all attributes are expired, the "expired" flag is set to True. """ + # we would like to assert that 'self.key is not None' here, + # but there are many cases where the mapper will expire + # a newly persisted instance within the flush, before the + # key is assigned, and even cases where the attribute refresh + # occurs fully, within the flush(), before this key is assigned. + # the key is assigned late within the flush() to assist in + # "key switch" bookkeeping scenarios. + if attribute_names is None: attribute_names = self.manager.keys() self.expired = True |