summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2014-11-06 17:41:16 -0500
committermike bayer <mike_mp@zzzcomputing.com>2014-11-06 17:41:16 -0500
commit9b1777288ba9f49248485ead0f77597dacf6de2e (patch)
treebaf74ee8d0b35ffe9bf944f94833ab71440b7a3b
parent8200c2cd35b3e85a636baabe8324b9ecbbd8fedf (diff)
parent4b09f1423b382336f29722490bab3a4c8c8607ea (diff)
downloadsqlalchemy-9b1777288ba9f49248485ead0f77597dacf6de2e.tar.gz
Merge pull request #149 from pbu88/small_error_reporting_improvement_update
Small improvement on FlushError can't update error message
-rw-r--r--lib/sqlalchemy/orm/persistence.py8
-rw-r--r--test/orm/test_unitofwork.py6
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index 28254cc10..6b8d5af14 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -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,
diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py
index 247c5e7a8..ae5a8ef60 100644
--- a/test/orm/test_unitofwork.py
+++ b/test/orm/test_unitofwork.py
@@ -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
)