]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Small improvement on FlushError can't update error message
authorPaulo Bu <pbu_98@yahoo.com>
Thu, 6 Nov 2014 20:14:17 +0000 (21:14 +0100)
committerPaulo Bu <pbu_98@yahoo.com>
Thu, 6 Nov 2014 20:14:17 +0000 (21:14 +0100)
Output in the error message the table name and the column name.

lib/sqlalchemy/orm/persistence.py
test/orm/test_unitofwork.py

index 28254cc1033866230529c4cd95654d551643dc0f..6b8d5af14578335b2256a09b7a3a7fa9b4f2004c 100644 (file)
@@ -375,12 +375,12 @@ def _collect_update_commands(uowtransaction, table, states_to_update):
                     params[col.key] = history.added[0]
             else:
                 pk_params[col._label] = history.unchanged[0]
+            if pk_params[col._label] is None:
+                raise orm_exc.FlushError(
+                    "Can't update table %s using NULL for primary "
+                    "key value on column %s" % (table, col))
 
         if params or value_params:
-            if None in pk_params.values():
-                raise orm_exc.FlushError(
-                    "Can't update table using NULL for primary "
-                    "key value")
             params.update(pk_params)
             yield (
                 state, state_dict, params, mapper,
index 247c5e7a80823dab3ece8183092e6897d3501f4a..ae5a8ef60f90bac8187935233e74cdb67e63035b 100644 (file)
@@ -2479,7 +2479,8 @@ class PartialNullPKTest(fixtures.MappedTest):
         t1.col2 = 5
         assert_raises_message(
             orm_exc.FlushError,
-            "Can't update table using NULL for primary key value",
+            "Can't update table t1 using NULL for primary "
+            "key value on column t1.col2",
             s.commit
         )
 
@@ -2492,7 +2493,8 @@ class PartialNullPKTest(fixtures.MappedTest):
         t1.col3 = 'hi'
         assert_raises_message(
             orm_exc.FlushError,
-            "Can't update table using NULL for primary key value",
+            "Can't update table t1 using NULL for primary "
+            "key value on column t1.col2",
             s.commit
         )