Strangely, if I add the following mapper_args, it is working with a warning 
(SAWarning: Dialect mssql+pyodbc does not support updated rowcount - 
versioning cannot be verified.) but not with an exception.

    __mapper_args__ = {
        'version_id_col': Created,
        'version_id_generator': False,
    }

jue...@gmail.com schrieb am Freitag, 26. Juni 2020 um 16:01:07 UTC+2:

> Here is the code I used (simplified):
>
> class Measurement(Base):
>     __tablename__ = 'Measurement'
>     __table_args__ = (
>         {'implicit_returning': False},  # Required because of some 
> triggers on this table
>     )
>
>     ID = Column(Integer, primary_key=True)
>     Created = Column(DATETIME2, nullable=False, 
> default=datetime.datetime.now)
>     IsCompleted = Column(BIT)
>     Completed = Column(DATETIME2)
>         
> measurement = Measurement(Part=motor_unit, 
> TestProcedureVersion=test_procedure)
> session.add(measurement)
> session.commit()
>
> # And Later:
> measurement.IsCompleted = True
> session.commit()  # --> This raises the StaleData Exception
>
>
>
> jue...@gmail.com schrieb am Freitag, 26. Juni 2020 um 15:57:32 UTC+2:
>
>> I'm currently working with sqlalchemy (Version 1.3.18) to access a 
>> Microsoft Server SQL Database (Version: 14.00.3223). I use pyodbc 
>> (Version 4.0.30)
>>
>> When I try to update a single object and try to update and commit the 
>> object, I run into a StaleDataError:
>>
>> StaleDataError: UPDATE statement on table 'Measurement' expected to 
>> update 1 row(s); 5051 were matched. 
>>
>> The update statement looks perfectly fine:
>>
>> 2020-06-26 15:50:59,872 INFO sqlalchemy.engine.base.Engine UPDATE 
>> tbm.[Measurement] SET [IsCompleted]=? WHERE tbm.[Measurement].[ID] = ?
>> 2020-06-26 15:50:59,872 INFO sqlalchemy.engine.base.Engine (True, 6248)
>>
>> Any Idea what's wrong with this.
>>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d71580a6-07a4-4495-af60-cd8164fcc899n%40googlegroups.com.

Reply via email to