postgres possibly forcing the "id" column in the col set but not pre-executing the sequence

Issue #759 resolved
Mike Bayer repo owner created an issue
c = Insert(values={'x':bindparam('x'), 'y':bindparam('y')}).compile()
engine.execute(c, {'x':5, 'y':7})



2007-08-23 17:59:34,573 INFO sqlalchemy.engine.base.Engine.0x..2c
INSERT INTO "Manager" (duties, name, id) VALUES (%(duties)s, %(name)s,
%(id)s)
2007-08-23 17:59:34,573 INFO sqlalchemy.engine.base.Engine.0x..2c
['torencho', 'duties': 'bany', 'id': None}, {'name':
'mnogoVojdMalkoIndianec', 'duties': 'lany', 'id': None}]({'name':)
2007-08-23 17:59:34,578 INFO sqlalchemy.engine.base.Engine.0x..2c
ROLLBACK
Traceback (most recent call last):
  File "insertMultiple.py", line 46, in <module>
    checkWith( db_postgres)
  File "insertMultiple.py", line 40, in checkWith
    dict( name= 'mnogoVojdMalkoIndianec', duties= 'lany'),
  File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 784, in
execute
    return Connection.executors[c](c)(self, object, multiparams, params)
  File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 815, in
_execute_clauseelement
    return self._execute_compiled(elem.compile(dialect=self.dialect,
parameters=param), multiparams, params)
  File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 826, in
_execute_compiled
    self.__execute_raw(context)
  File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 838, in
__execute_raw
    self.__executemany(context)
  File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 872, in
__executemany
    raise exceptions.SQLError(context.statement, context.parameters,
e)
sqlalchemy.exceptions.IntegrityError: (IntegrityError) null value in
column "id" violates not-null constraint
 'INSERT INTO "Manager" (duties, name, id) VALUES (%(duties)s, %
(name)s, %(id)s)' ['torencho', 'duties': 'bany', 'id': None},
{'name': 'mnogoVojdMalkoIndianec', 'duties': 'lany', 'id': None}]({'name':)

ensure that the sequence definitely fires off when the column is placed into the values clause, or if autoincrement=False, no sequence/PK activity should fire off.

the "inline=True" feature should disable the sequence from being placed within the statement at all (but that should probably be a separate ticket).

Comments (3)

  1. Mike Bayer reporter

    this is confirmed, i busted pre-execute of sequences for executemany. i have a branch in progress to overhaul "inlining" of inserts and fix this at the same time.

  2. Log in to comment