diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-30 17:52:28 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-30 17:52:28 -0500 |
| commit | 1f057987da6ee5ca6da94384a0603e4fee13dff8 (patch) | |
| tree | 8d09ed1b9d25ffd8d887b21be67bc2644080cf01 | |
| parent | 6a853837b99f27dbecf7c6eb39f54446bd91e258 (diff) | |
| download | sqlalchemy-1f057987da6ee5ca6da94384a0603e4fee13dff8.tar.gz | |
- [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]
| -rw-r--r-- | CHANGES | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 19 | ||||
| -rw-r--r-- | test/orm/test_unitofwork.py | 10 |
3 files changed, 25 insertions, 10 deletions
@@ -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 |
