From: Mike Bayer Date: Mon, 30 Jan 2012 22:52:28 +0000 (-0500) Subject: - [bug] Scaled back the test applied within X-Git-Tag: rel_0_7_6~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f057987da6ee5ca6da94384a0603e4fee13dff8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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] --- diff --git a/CHANGES b/CHANGES index ac787593af..a9c823d28d 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 4c952c1fd5..bf277664ad 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 362ff35ca1..b0dbfe3907 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