Hello, apologies for the delay.

I'm using SQL Server. Updates using the code below work normally. However, 
when I try to change the object directly and apply commit, I receive the 
mentioned error.
stmt = update(PPESSOA).where(PPESSOA.CODIGO == 
ppessoa.CODIGO).values(EMAILPESSOAL=data['EMAIL'])
session.execute(stmt)
session.commit() 

The connection string is:

SQLALCHEMY_TCLOUD_DATABASE_URI = 
'mssql://'+TCLOUD_DATABASE_USERNAME+':'+TCLOUD_DATABASE_PASSWORD_UPDATED+'@'+TCLOUD_DATABASE_HOST+':'+TCLOUD_DATABASE_PORT+'/'+TCLOUD_DATABASE_NAME+'?driver='+TCLOUD_DATABASE_DRIVER

Driver is:

libmsodbcsql-17.10.so.4.1 

Thank you for all!


Em terça-feira, 22 de agosto de 2023 às 15:51:47 UTC-3, Mike Bayer escreveu:

> if it's fully reproducible every time with both statements, then this 
> suggests something is happening with the database server itself, such as 
> some kind of issue with triggers getting involved or something.   In 
> particular if this is MS SQL Server and there are triggers involved, the 
> updated rowcount might not be working correctly and extra steps might need 
> to be taken to turn off SQLAlchemy's rowcount facilities.
>
> you want to turn on `echo=True` and see that the expected UPDATE statement 
> takes place.  Then you might want to try running those UPDATE statements 
> directly on the database and see that they work.
>
> What database backend, what database driver, and is the issue only 
> reproducible in a single environment or can it be reproduced elsewhere?
>
>
> On Tue, Aug 22, 2023, at 2:42 PM, Leandro Lázaro wrote:
>
> Hello
>
> First, thanks for building this library. God bless you
>
>
> I've been trying to understand what's going on for days.
>
> This code works fine:
>
> https://pastebin.com/fLTnB8jy
>
> But if I try to modify any other parameter like PERSONAL EMAIL I get the 
> error:
>
> sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' 
> expected to update 1 row(s); 0 were matched 
>
> Example: https://pastebin.com/EwdwLRcp
>
> Tank you
>
>
> -- 
> 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+...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/c2939c34-4d95-4fe8-b697-afc705b47a11n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/c2939c34-4d95-4fe8-b697-afc705b47a11n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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/65034fdf-0743-4f6a-8f4b-7b947364880dn%40googlegroups.com.

Reply via email to