a stale data error with date/time fields is usually a mismatch between the 
date/time value you have locally and the one that's in the database,. assuming 
you are using the datetime column as a "version_id" in your mapping.     Issues 
like strings vs. datetimes and/or microseconds portions being present or 
non-present are the most common.

would need to see SQL debug logging to have more insight / confirm that's the 
problem.

On Fri, Sep 1, 2023, at 11:59 AM, Dumitru Gîra wrote:
> I have encountered a very strange behaviour and I don't know where to look 
> further.
> I have a small API https://pastebin.com/qW01jNz8 with 2 endpoints: one to 
> update the name (VARCHAR) and one to update the last_login (DATETIME).
> 
> If I make 10 consecutive requests to /update-string - everything works as 
> expected.
> If I make 10 consecutive requests to /update-datetime - the first request 
> works and other 9 fail with sqlalchemy.orm.exc.StaleDataError.
> NOTE: putting a time.sleep(1) after every request does not raise the error
> 
> Consecutive requests are being made using the simple snippet
> import requests
> for i in range(10):
>     r = requests.put('http://0.0.0.0:8080/update-datetime')
>     print(r.text, r.code)
> 
> The source code and the logs are in above link and for the reference I am 
> using:
> - MySQL 8.0, but the same happens with 5.7
> - mysqldb connector, but the same happens with pymysql
> - SQLAlchemy==1.4.49
> 
> Is this related to MySQL and specifically to date/time related fields (as the 
> same happens with TIMESTAMP) or can it be something from SQLAlchemy side?
> Any directions would be highly appreciated.
> 
> Kind regards,
> Dumitru
> 
> 
> -- 
> 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/e53169bd-617f-41f3-b9d3-8002ea75496an%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/e53169bd-617f-41f3-b9d3-8002ea75496an%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/8ddfacc0-e23b-4672-b05f-92b2517d830a%40app.fastmail.com.

Reply via email to