diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-06-04 20:04:29 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-06-04 20:04:29 -0400 |
commit | d9a2c64a412feb5341eb1b7f27452af30455b7c9 (patch) | |
tree | 9ad9bcd9ddb7643acd61c87142742542289d92ce | |
parent | 8c09969d44c7d66634c3a392f17383ebfacb2881 (diff) | |
download | sqlalchemy-d9a2c64a412feb5341eb1b7f27452af30455b7c9.tar.gz |
- Modify the text of the message which occurs
when the "identity" key isn't detected on
flush, to include the common cause that
the Column isn't set up to detect
auto-increment correctly; [ticket:2170].
Also in 0.6.8.
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 13 | ||||
-rw-r--r-- | test/orm/test_unitofwork.py | 4 |
3 files changed, 18 insertions, 6 deletions
@@ -18,6 +18,13 @@ CHANGES create multiple event listeners for subclasses either. [ticket:2180] + - Modify the text of the message which occurs + when the "identity" key isn't detected on + flush, to include the common cause that + the Column isn't set up to detect + auto-increment correctly; [ticket:2170]. + Also in 0.6.8. + - sql - Fixed bug whereby metadata.reflect(bind) would close a Connection passed as a diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 8f8770a3b..29353c4b7 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1085,10 +1085,15 @@ class Session(object): 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 occurring at an ' - 'inappropriate time, such as during a load ' - 'operation.' % mapperutil.state_str(state)) + raise exc.FlushError( + "Instance %s has a NULL identity key. If this is an " + "auto-generated value, check that the database table " + "allows generation of new primary key values, and that " + "the mapped Column object is configured to expect these " + "generated values. Ensure also that this flush() is " + "not occurring at an inappropriate time, such as within " + "a load() event." % mapperutil.state_str(state) + ) if state.key is None: state.key = instance_key diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index 8b2787d12..10d13ec8a 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -2469,7 +2469,7 @@ class PartialNullPKTest(fixtures.MappedTest): assert_raises_message( sa.exc.FlushError, r"Instance \<T1 at .+?\> has a NULL " - "identity key. Check if this flush is occurring " - "at an inappropriate time, such as during a load operation.", + "identity key. If this is an auto-generated value, " + "check that the database table allows generation ", s.commit ) |