diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-09-09 19:21:23 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-09-09 19:21:23 -0400 |
commit | 9674b4bf176539400ba10de41c32186873d4dc13 (patch) | |
tree | a3edbc7767a57eec13226f205bddac26b4b3eb0c /lib/sqlalchemy/orm/session.py | |
parent | a48ee1b397249302305eb00998e287c62d898c68 (diff) | |
download | sqlalchemy-9674b4bf176539400ba10de41c32186873d4dc13.tar.gz |
- collection docs
- Added an assertion during flush which ensures
that no NULL-holding identity keys were generated
on "newly persistent" objects.
This can occur when user defined code inadvertently
triggers flushes on not-fully-loaded objects.
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index d906df2a3..54b41fcc6 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1018,6 +1018,14 @@ class Session(object): if obj is not None: instance_key = mapper._identity_key_from_state(state) + + if _none_set.issubset(instance_key[1]) and \ + not mapper.allow_partial_pks or \ + _none_set.issuperset(instance_key[1]): + raise exc.FlushError('Instance %s has a NULL identity ' + 'key. Check if this flush is occuring at an ' + 'inappropriate time, such as during a load ' + 'operation.' % mapperutil.state_str(state)) if state.key is None: state.key = instance_key |