Skip to content
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

identity insert switch fails for INSERT with insert.values({col: <expr>}) only #4499

Closed
zzzeek opened this issue Feb 13, 2019 · 3 comments
Closed
Labels
bug Something isn't working SQL Server Microsoft SQL Server, e.g. mssql sql
Milestone

Comments

@zzzeek
Copy link
Member

zzzeek commented Feb 13, 2019

pretty specific stuff

from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import Integer
from sqlalchemy import literal
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class A(Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)

e = create_engine("mssql+pyodbc://scott:tiger^5HHH@mssql2017:1433/test?driver=ODBC+Driver+13+for+SQL+Server", echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)

with e.connect() as conn:
    # passes
    conn.execute(
        A.__table__.insert(),
        id=1
    )

    # passes
    conn.execute(
        A.__table__.insert().values(id=literal(2))
    )

    # passes
    conn.execute(
        A.__table__.insert().values({A.__table__.c.id: 3})
    )

    # fails
    conn.execute(
        A.__table__.insert().values({A.__table__.c.id: literal(4)})
    )

@zzzeek zzzeek added bug Something isn't working sql SQL Server Microsoft SQL Server, e.g. mssql labels Feb 13, 2019
@zzzeek zzzeek added this to the 1.2.x milestone Feb 13, 2019
@zzzeek
Copy link
Member Author

zzzeek commented Feb 13, 2019

this is failing in the test suite as of c1f310d as we have a test running on that.

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

Set IDENTITY_INSERT for insert.values({column: expr}) https://gerrit.sqlalchemy.org/1133

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the rel_1_2 branch:

Set IDENTITY_INSERT for insert.values({column: expr}) https://gerrit.sqlalchemy.org/1134

sqlalchemy-bot pushed a commit that referenced this issue Feb 13, 2019
Fixed bug where the SQL Server "IDENTITY_INSERT" logic that allows an INSERT
to proceed with an explicit value on an IDENTITY column was not detecting
the case where :meth:`.Insert.values` were used with a dictionary that
contained a :class:`.Column` as key and a SQL expression as a value.

Fixes: #4499
Change-Id: Ia61cd6524b030b40a665db9c20771f0c5aa5fcd7
(cherry picked from commit 71d6427)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SQL Server Microsoft SQL Server, e.g. mssql sql
Projects
None yet
Development

No branches or pull requests

2 participants