AsyncEngine always returns UTC time for datetime column

17 views
Skip to first unread message

Ivan Randjelovic

unread,
Sep 14, 2021, 7:03:27 AMSep 14
to sqlalchemy
Hi all,

I am trying to figure it out why AsyncEngine always returns UTC time for datetime column, any help is appreciated?

I am working with sqlalchemy core and async engine. Column definition:
Column('test', DateTime(timezone=True), nullable=False)

Also tried with this, but no luck:
_connect_args = {'server_settings': {'timezone': ''America/New_York''}}
async_db: AsyncEngine = create_async_engine(async_url_from_config(), connect_args=_connect_args)


When I tried with regular create_engine, everything worked as expected with the same database data.
Data in the database (configured for New York) contains timezone info:

test | 2021-08-26 16:02:46.057288-04

BR,

Ivan


Jonathan Vanasco

unread,
Sep 14, 2021, 6:20:07 PMSep 14
to sqlalchemy
Can you share the database drivers / dialects you use?  The discrepancy could be there.

Ivan Randjelovic

unread,
Sep 15, 2021, 3:27:17 AMSep 15
to sqlalchemy
Hi Jonathan,

I use postgres docker image from docker hub version 12 with this settings in docker-compose file:
db:
    image: postgres:12
    environment:
        POSTGRES_USER: test_db
        POSTGRES_DB: test_db
        POSTGRES_PASS: test_db
        POSTGRES_HOST_AUTH_METHOD: trust
       TZ: America/New_York
volumes:
    - pgdata:/var/lib/postgresql/data
ports:
    - 5532:5432
restart: unless-stopped
networks:
    - postgres-net

Also when I create async engine the url is like this (copied from sqlaclemy docs):

Regular create_engine (not async) returns datetime with correct timezone info as expected, so this is an issue only when I use async engine basically on the same way as regular one.

Thanks,
Ivan

Mike Bayer

unread,
Sep 15, 2021, 8:49:03 AMSep 15
to noreply-spamdigest via sqlalchemy
using the "sync" engine I would assume you are using psycopg2, which is going to use native Postgresql client libraries.  asyncpg I think is written in cython and doesn't actually use libpq if im reading it correctly.

therefore the difference may be a libpq related setting of the local timezone when the program runs, though I can't produce specific links to support this theory.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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.

Reply all
Reply to author
Forward
0 new messages