sqlalchemy: alter ORM-level "returned rows" checks to only warn if driver returns -1 or None
I’m using flask-sqlalchemy to update mssql record,but returns -1.
Library versions
SQLAlchemy 1.3.11 Flask-SQLAlchemy 2.4.1 pyodbc 4.0.27 flask 1.1.1
code1
ret = db.session.query(XXX).filter_by(id=1).update({"xxx": "xxxx"})
print("ret", ret)
db.session.commit()
The ret is -1, but the record has been modified .
code2
obj = XXX.query.filter_by(id=q).first()
obj .xx = "xxx"
db.session.commit()
Raise a error: sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table ‘XXX’ expected to update 1 row(s); -1 were matched. and the modify did not successed.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 21 (16 by maintainers)
There are a ton of different use cases that do NOT work after doing “SET NOCOUNT ON”. I tried a lot yesterday evening to update a value on a row, and every single attempt failed. Might be, because the called SQLA code is the same in the end - nevertheless, I wanted to mention that not only the update-function is affected…