Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlalchemy throws ValueError: datetime not corresponding to isoformat #14

Open
MRB60 opened this issue Apr 24, 2023 · 1 comment
Open

Comments

@MRB60
Copy link

MRB60 commented Apr 24, 2023

With Sqlalchemy 2.0:
when defining a DateTime column in table model as:
..., default=datetime.datetime.utcnow)

I get the following error at query:
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 521, in <listcomp> return [make_row(row) for row in rows] File "lib/sqlalchemy/cyextension/resultproxy.pyx", line 25, in sqlalchemy.cyextension.resultproxy.BaseRow.__init__ File "lib/sqlalchemy/cyextension/processors.pyx", line 34, in sqlalchemy.cyextension.processors.str_to_datetime ValueError: Invalid isoformat string: '2023-04-24 08:54:34.53687'
it seem to work with:
datetime.datetime.utcnow()
But that datetime is then corresponding to table creation time and not row creation time.

Any suggestion what I can do about it?
The issue does not occur when using Sqlite3.

@MRB60
Copy link
Author

MRB60 commented Apr 24, 2023

UPDATE:
omitting microseconds in datetime.utcnow fixed the problem.

datetime seem to be stored correctly (e.g. 2023-04-24T09:02:02.682648Z via CLI) but when fetched via Sqlalchemy query,
it seems as datetime microsecond part is truncated to 5 digits. Must be 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant