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

A timezone error on python3.12 and alembic[tz]? #1556

Closed
Danipulok opened this issue Oct 25, 2024 · 7 comments
Closed

A timezone error on python3.12 and alembic[tz]? #1556

Danipulok opened this issue Oct 25, 2024 · 7 comments
Labels
bug Something isn't working use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@Danipulok
Copy link
Contributor

Describe the bug
Async API mode.
I used config templates from here.
I used pip install alembic[tz]:

$ pip install alembic[tz]==1.13.3
Requirement already satisfied: alembic==1.13.3 in d:\code\project\.venv\lib\site-packages (from alembic[tz]==1.13.3) (1.13.3)
Requirement already satisfied: SQLAlchemy>=1.3.0 in d:\code\project\.venv\lib\site-packages (from alembic==1.13.3->alembic[tz]==1.13.3) (2.0.36)
Requirement already satisfied: Mako in d:\code\project\.venv\lib\site-packages (from alembic==1.13.3->alembic[tz]==1.13.3) (1.3.6)
Requirement already satisfied: typing-extensions>=4 in d:\code\project\.venv\lib\site-packages (from alembic==1.13.3->alembic[tz]==1.13.3) (4.12.2)
Requirement already satisfied: greenlet!=0.4.17 in d:\code\project\.venv\lib\site-packages (from SQLAlchemy>=1.3.0->alembic==1.13.3->alembic[tz]==1.13.3) (3.1.1)     
Requirement already satisfied: MarkupSafe>=0.9.2 in d:\code\project\.venv\lib\site-packages (from Mako->alembic==1.13.3->alembic[tz]==1.13.3) (3.0.2)

But when I run alembic revision --autogenerate -m "msg", I get:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.autogenerate.compare] Detected added table 'users'
INFO  [alembic.autogenerate.compare] Detected added index ''ix_users_created_at'' on '('created_at',)'
ERROR [alembic.util.messaging] Can't locate timezone: UTC
FAILED: Can't locate timezone: UTC

Expected behavior
Everything should work if I installed alembic[tz]?
But I also found this issue on SO: https://stackoverflow.com/questions/77698777/how-to-change-timezone-in-alembic-for-sqlalchemy
After I install tzdata, the same command stated working.

To Reproduce
Use this alembic.ini: https://github.com/sqlalchemy/alembic/blob/bd50ba325b10a1a9cdb452fe40c96f959825797c/alembic/templates/async/alembic.ini.mako
And add:

timezone = UTC

Versions.

  • OS: Windows 10
  • Python: 3.12.3
  • Alembic: 1.13.3
  • SQLAlchemy: 2.0.36
  • Database: postgres
  • DBAPI: asyncpg==0.30.0
@Danipulok Danipulok added the requires triage New issue that requires categorization label Oct 25, 2024
@zzzeek
Copy link
Member

zzzeek commented Oct 25, 2024

if you're on python 3.12 the alembic[tz] target does not install anything additional, it just installs zoneinfo.

per zoneinfo: https://docs.python.org/3/library/zoneinfo.html it uses system databases if available otherwise will fall back to tzdata

@CaselIT why do we have this target in the first place and should it install tzdata on all versions?

@Danipulok
Copy link
Contributor Author

Thanks a lot for the quick response!
Really appreciate

Hm, this seems really strange, because if I uninstall tzdata, I get the following:

$ python -c "from zoneinfo import available_timezones; print(available_timezones())"
set()

When I install tzdata again, everything's okay:

$ python -c "from zoneinfo import available_timezones; print(available_timezones())"
{'America/Puerto_Rico', 'America/Panama', 'America/Port_of_Spain', 'Pacific/Saipan', 'Europe/Bratislava', 'Pacific/Honolulu', 'Europe/Luxembourg', 'America/Recife', 'America/Cuiaba', 'America/Paramarib
o', 'Europe/Sarajevo', 'America/North_Dakota/New_Salem', 'Asia/Gaza', 'America/Ojinaga', 'Asia/Macau', 'Asia/Manila', 'Asia/Oral', 'America/Buenos_Aires', 'Europe/Ljubljana', 'Australia/North', 'Asia/C
hita', 'US/Samoa', 'Pacific/Galapagos' ...

So I think it would be useful if tzdata would always be installed on alembic[tz], if by default zoneinfo does not provide any timezones?

@CaselIT
Copy link
Member

CaselIT commented Oct 25, 2024

@CaselIT why do we have this target in the first place and should it install tzdata on all versions?

if by default zoneinfo does not provide any timezones?

I incorrectly assumed that utc etc was always included, if not then I think it makes sense to always install tzdata in the tz extra

@CaselIT CaselIT added bug Something isn't working use case not quite a feature and not quite a bug, something we just didn't think of and removed requires triage New issue that requires categorization labels Oct 25, 2024
@Danipulok
Copy link
Contributor Author

Maybe then I should create a PR for this?
I would really like to do it

The question is should I pin the tzdata version or no?

@CaselIT
Copy link
Member

CaselIT commented Oct 25, 2024

Maybe then I should create a PR for this?

that would be great!

The question is should I pin the tzdata version or no?

I don't think we need to, unless zoneinfo requires a min version to work

@sqla-tester
Copy link
Collaborator

Danipulok has proposed a fix for this issue in the main branch:

fix(requirements): add tzdata to tz extras; fixes #1556 https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5583

1 similar comment
@sqla-tester
Copy link
Collaborator

Danipulok has proposed a fix for this issue in the main branch:

fix(requirements): add tzdata to tz extras; fixes #1556 https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5583

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants