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

Pendulum can not find timezone on Alpine docker, resulting in .now() being broken #715

Closed
jonaslb opened this issue Jun 16, 2023 · 1 comment · Fixed by #733
Closed

Pendulum can not find timezone on Alpine docker, resulting in .now() being broken #715

jonaslb opened this issue Jun 16, 2023 · 1 comment · Fixed by #733

Comments

@jonaslb
Copy link

jonaslb commented Jun 16, 2023

  • [ x ] I am on the latest Pendulum version.
    • Tested on both latest stable and the 3.0.0a1 release
  • [ x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Docker image alpine:3.18, apk add python3 py3-pip && pip install pendulum
  • Pendulum version: Tested with both 2.1.2 and 3.0.0a1

Issue

On the alpine image, pendulum cannot find the local timezone. Thus import pendulum; pendulum.now() gives the exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/pendulum/__init__.py", line 206, in now
    return DateTime.now(tz)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pendulum/datetime.py", line 137, in now
    dt = datetime.datetime.now(local_timezone())
                               ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pendulum/tz/__init__.py", line 66, in local_timezone
    return get_local_timezone()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 33, in get_local_timezone
    tz = _get_system_timezone()
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 61, in _get_system_timezone
    return _get_unix_timezone()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 244, in _get_unix_timezone
    raise RuntimeError("Unable to find any timezone configuration")
RuntimeError: Unable to find any timezone configuration

Curiously, this stdlib approach works totally fine: from datetime import UTC, datetime; datetime.now(UTC).astimezone().tzinfo (gives UTC, as expected).

I saw that there was a fairly recent change to have pendulum timezone depend on stdlib. Perhaps that should be expanded to use the above approach to obtaining tzinfo as well - most likely more reliable?

@tedmiston
Copy link

tedmiston commented Jun 19, 2023

I'm getting this one too.

Going to just go off of Alpine for now as a workaround. ¯\_(ツ)_/¯

@sdispater sdispater mentioned this issue Aug 15, 2023
2 tasks
Secrus pushed a commit that referenced this issue Aug 15, 2023
* Ensure string representations match the standard library

Fixes #662

* Fix deepcopy of durations

Fixes #714

* Default to UTC if not local timezone can be found

Fixes #715
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.

2 participants