]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Scaled back the test applied within
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Jan 2012 22:52:28 +0000 (17:52 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Jan 2012 22:52:28 +0000 (17:52 -0500)
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]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/test_unitofwork.py

diff --git a/CHANGES b/CHANGES
index ac787593af270971a408ecb03b994a9513237df6..a9c823d28deb9b99c9b62c53afacc124ebffc114 100644 (file)
--- 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
index 4c952c1fd5f8632c802fc47b7965282cf5a52bb5..bf277664ad383b8eb8c0036a89061d4f0008e2fa 100644 (file)
@@ -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))
 
index 362ff35ca1f3ffceedb5ca7e7099e1b973a19703..b0dbfe3907db8e4ea8c81eac7bd42fe54e4698c9 100644 (file)
@@ -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