-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Insert multiple rows fails when using a column's default value #3288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Michael Bayer (@zzzeek) wrote: it says "if c.key in row else param". the param is there, the issue here lies only in the conversion to positional. Test cases are super helpful, here's mine, which if you use a named format, passes:
if we use |
Michael Bayer (@zzzeek) wrote: now what is odd is why that positional conversion isn't working, so in the logic you mention I think we might need to make a new bindparam() object with the same name, perhaps, i need to recall how that case is supposed to work. |
Michael Bayer (@zzzeek) wrote: ok yeah 'param' there is just the string so somehting has to happen that will add an entry to positiontup each time there |
Michael Bayer (@zzzeek) wrote: the contract of Python side default callables is that they be called for each row individually. This functionality is not at all built into the "multi VALUES" facility right now, and will change the behavior of an application that currently makes use of python-callable defaults with a name-based paramstyle. to accomplish this means some major changes in crud.py which I'll do today but this would be definitely too destabilizing for 0.9. |
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote:
→ 92cc232 |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: that was a total crapshow. there's a migration guide on that one coming up in the next readthedocs build. |
Migrated issue, originally created by Matthew Booth
OpenStack's oslo.db contains a TimestampMixin, which defines a created_at column:
Attempting to insert multiple rows without explicitly specifying this column will fail. e.g.:
DBError: (sqlite3.ProgrammingError) Incorrect number of bindings supplied. The current statement uses 20, and there are 19 supplied. [SQL: u'INSERT INTO fixed_ips (created_at, deleted, address, network_id, virtual_interface_id, instance_uuid, allocated, leased, reserved, host) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('2015-01-13 14:04:51.046323', 0, '192.168.1.5', 1, None, 'd4473f3a-dbb9-43ce-a30b-51a4583ead5f', 0, 0, 0, '127.0.0.1', 0, '192.168.1.6', 2, None, 'd4473f3a-dbb9-43ce-a30b-51a4583ead5f', 1, 0, 0, 'localhost')]
In the above case, the caller is not passing a value for created_at:
The cause seems to be in _extend_values_for_multiparams:
Note how the tricky innermost code only calls _create_bind_param() 'if c.key in row'. In the above case, created_at is not in the statement parameters. The first row is handled separately, and correctly adds a bind parameter for created_at, hence the error message complains about having only 19 bind values.
The text was updated successfully, but these errors were encountered: