From: Mike Bayer Date: Sun, 5 Jun 2011 00:09:21 +0000 (-0400) Subject: - Modify the text of the message which occurs X-Git-Tag: rel_0_6_8~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=907a4988408a8cb3748b657a7911426c99689582;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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]. --- diff --git a/CHANGES b/CHANGES index 7f9063a990..545d79bc9a 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,12 @@ CHANGES alias would fail if logging were used, due to unescaped % sign in the alias name. [ticket:2171] + - 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]. + - sql - Fixed bug whereby if FetchedValue was passed to column server_onupdate, it would not diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 610fc6362a..61ceeeeb09 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1045,10 +1045,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 85c2c2516b..408810d1b9 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -2320,10 +2320,10 @@ class DontAllowFlushOnLoadingObjectTest(_base.MappedTest): # the population process would continue after the erroneous flush # and thing would right themselves. assert_raises_message(sa.orm.exc.FlushError, - 'has a NULL identity key. Check if this ' - 'flush is occurring at an inappropriate ' - 'time, such as during a load operation.', - sess.query(T1).first) + r"Instance \ has a NULL " + "identity key. If this is an auto-generated value, " + "check that the database table allows generation ", + sess.query(T1).first)