summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/orm/mapper.py19
-rw-r--r--test/orm/test_unitofwork.py10
3 files changed, 25 insertions, 10 deletions
diff --git a/CHANGES b/CHANGES
index ac787593a..a9c823d28 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,12 @@ CHANGES
establishing only a subset of classes
as reflected.
+ - [bug] Scaled back the test applied within
+ flush() to check for UPDATE against partially
+ NULL PK within one table to only actually
+ happen if there's really an UPDATE to occur.
+ [ticket:2390]
+
0.7.5 (January 28, 2012)
=====
- orm
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 4c952c1fd..bf277664a 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -2095,7 +2095,7 @@ class Mapper(object):
insert.append((state, state_dict, params, mapper,
connection, value_params, has_all_pks))
else:
- hasdata = False
+ hasdata = hasnull = False
for col in mapper._cols_by_table[table]:
if col is mapper.version_id_col:
params[col._label] = \
@@ -2169,23 +2169,22 @@ class Mapper(object):
del params[col.key]
value = history.added[0]
params[col._label] = value
- if value is None and hasdata:
- raise sa_exc.FlushError(
- "Can't update table "
- "using NULL for primary key "
- "value")
+ if value is None:
+ hasnull = True
else:
hasdata = True
elif col in pks:
value = state.manager[prop.key].\
impl.get(state, state_dict)
if value is None:
- raise sa_exc.FlushError(
- "Can't update table "
- "using NULL for primary "
- "key value")
+ hasnull = True
params[col._label] = value
if hasdata:
+ if hasnull:
+ raise sa_exc.FlushError(
+ "Can't update table "
+ "using NULL for primary "
+ "key value")
update.append((state, state_dict, params, mapper,
connection, value_params))
diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py
index 362ff35ca..b0dbfe390 100644
--- a/test/orm/test_unitofwork.py
+++ b/test/orm/test_unitofwork.py
@@ -2483,3 +2483,13 @@ class PartialNullPKTest(fixtures.MappedTest):
"check that the database table allows generation ",
s.commit
)
+
+ def test_dont_complain_if_no_update(self):
+ T1 = self.classes.T1
+ s = Session()
+ t = T1(col1="1", col2=None)
+ s.add(t)
+ s.commit()
+
+ t.col1 = "1"
+ s.commit() \ No newline at end of file