pyodbc can't do rowcount with OUTPUT inserted.name

Issue #4062 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'
    name = Column(String(50), 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)

s = Session(e)

a1 = A(name='a1')
s.add(a1)

s.commit()

a1.name = A.name + '2'
s.commit()

this hits return_defaults() and then fails on rowcount. need a new dialect flag.

Comments (2)

  1. Mike Bayer reporter

    Add new sane_rowcount_w_returning flag

    Added a new class of "rowcount support" for dialects that is specific to when "RETURNING", which on SQL Server looks like "OUTPUT inserted", is in use, as the PyODBC backend isn't able to give us rowcount on an UPDATE or DELETE statement when OUTPUT is in effect. This primarily affects the ORM when a flush is updating a row that contains server-calcluated values, raising an error if the backend does not return the expected row count. PyODBC now states that it supports rowcount except if OUTPUT.inserted is present, which is taken into account by the ORM during a flush as to whether it will look for a rowcount.

    ORM tests are implicit in existing tests run against PyODBC

    Fixes: #4062 Change-Id: Iff17cbe4c7a5742971ed85a4d58660c18cc569c2

    → <<cset b9b1e374bfbc>>

  2. Mike Bayer reporter

    Additional fixes to sane rowcount

    Implement rowcount assertions and single row check for post_update as well as deletes.

    Change-Id: I4e5ba7e8747bf0e0b41f569089eb8cdbf064b7a9 Fixes: #4062

    → <<cset c4d6596ba3df>>

  3. Log in to comment