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

Database timezone ignored for timestamptz #1006

Open
TheJJ opened this issue Feb 19, 2023 · 4 comments · May be fixed by MagicStack/py-pgproto#21
Open

Database timezone ignored for timestamptz #1006

TheJJ opened this issue Feb 19, 2023 · 4 comments · May be fixed by MagicStack/py-pgproto#21

Comments

@TheJJ
Copy link

TheJJ commented Feb 19, 2023

  • asyncpg version: 0.27.0
  • PostgreSQL version: 15.1
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : local
  • Python version: 3.10.9
  • Platform: Linux
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: no
  • If you built asyncpg locally, which version of Cython did you use?: 0.29.33
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : not tested, since unlikely

I would expect the datetime.datetime object has the same timezone as psql or python determines (CET).

Instead, asyncpg sets the timezone to UTC.

psql shell, displays UTC+1 = CET properly:

=> select now()::timestamptz;
 2023-02-19 01:53:28.453411+01

python-shell:

>>> loop = asyncio.new_event_loop()
>>> c = loop.run_until_complete(asyncpg.connect(database='lol'))
>>> loop.run_until_complete(c.fetch("select now()::timestamptz"))
[<Record now=datetime.datetime(2023, 2, 19, 0, 54, 39, 597496, tzinfo=datetime.timezone.utc)>]
# ^ here, i'd expect it to be with tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET')

# because python does the same thing when having timezoned timestamps:
>>> datetime.datetime.now().astimezone()
datetime.datetime(2023, 2, 19, 1, 57, 12, 260030, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
@adriangb
Copy link

adriangb commented Feb 19, 2023

Dupe of #481 ?

@TheJJ
Copy link
Author

TheJJ commented Feb 22, 2023

I've submitted a fix at MagicStack/py-pgproto#21

@TheJJ
Copy link
Author

TheJJ commented Apr 8, 2023

can this please be reviewed?

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

Successfully merging a pull request may close this issue.

3 participants
@TheJJ @adriangb and others