From 68a6701c6d72d6c6ef1ea2b7d615273659e8b735 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 8 Sep 2015 13:00:26 -0400 Subject: - Fixed bug in :meth:`.Session.bulk_save_objects` where a mapped column that had some kind of "fetch on update" value and was not locally present in the given object would cause an AttributeError within the operation. fixes #3525 --- lib/sqlalchemy/orm/persistence.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/orm') diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index c785a4dee..64872288e 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -672,6 +672,8 @@ def _emit_update_statements(base_mapper, uowtransaction, connection, value_params in records: c = cached_connections[connection].\ execute(statement, params) + + # TODO: why with bookkeeping=False? _postfetch( mapper, uowtransaction, @@ -694,6 +696,8 @@ def _emit_update_statements(base_mapper, uowtransaction, execute(statement, multiparams) rows += c.rowcount + + # TODO: why with bookkeeping=False? for state, state_dict, params, mapper, \ connection, value_params in records: _postfetch( @@ -964,6 +968,8 @@ def _postfetch(mapper, uowtransaction, table, after an INSERT or UPDATE statement has proceeded for that state.""" + # TODO: bulk is never non-False, need to clean this up + prefetch_cols = result.context.compiled.prefetch postfetch_cols = result.context.compiled.postfetch returning_cols = result.context.compiled.returning @@ -996,7 +1002,7 @@ def _postfetch(mapper, uowtransaction, table, mapper.class_manager.dispatch.refresh_flush( state, uowtransaction, load_evt_attrs) - if postfetch_cols: + if postfetch_cols and state: state._expire_attributes(state.dict, [mapper._columntoproperty[c].key for c in postfetch_cols if c in -- cgit v1.2.1