Skip to content

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

@jonaslb

Description

@jonaslb
  • [ 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions