[Sqlalchemy-tickets] Issue #3253: Executing table insert with variable items yields unexpected resu
Brought to you by:
zzzeek
|
From: Moritz B. <iss...@bi...> - 2014-11-20 18:07:13
|
New issue 3253: Executing table insert with variable items yields unexpected results https://bitbucket.org/zzzeek/sqlalchemy/issue/3253/executing-table-insert-with-variable-items Moritz Beber: I recently stumbled over the following *feature*: Suppose I have a table model `Dummy` inheriting from the declarative base: ```python class Dummy(Base): a = Column(Integer) b = Column(Integer) ``` In order to efficiently insert many rows into the table I build a list `values` of `dict`s and run the following commands in a valid session: ```python session.execute(Dummy.__table__.insert(), values) session.commit() ``` Now the kicker is, which needs to be documented I think, that if the first `dict` in that list is, for example, `{"a": 3}` and any following `dict` contains both `a` and `b`, all the following `b`s are ignored, i.e., None. If the first is `{"a": 1, "b": 3}` and any following contains only one key then this causes a `StatementError`. If both pairs are present in the dictionary but one of them is `None` this works perfectly. So for the sake of efficiency, I can understand why it works the way that it does but I didn't see this written down anywhere and I think it should be. Maybe it belongs in the insert tutorial, not sure. |