Skip to content

Fix arrow.get() crash when tzinfo kwarg is explicitly None - #1339

Open
mayuriphad wants to merge 1 commit into
arrow-py:masterfrom
mayuriphad:fix-tzinfo-none-kwarg
Open

Fix arrow.get() crash when tzinfo kwarg is explicitly None#1339
mayuriphad wants to merge 1 commit into
arrow-py:masterfrom
mayuriphad:fix-tzinfo-none-kwarg

Conversation

@mayuriphad

Copy link
Copy Markdown

Summary

Fixes #1259.

ArrowFactory.get() decides whether kwargs should be routed to the direct Arrow(...) constructor (the 3+ positional args path) based on whether the only kwarg present is tzinfo. It did this by checking tz is None, which cannot distinguish between "tzinfo was not passed at all" and "tzinfo=None was passed explicitly". As a result:

arrow.get('2013-01-01', 'YYYY-MM-DD', tzinfo=None)

was routed to self.type(*args, **kwargs) (the constructor path meant for calls like arrow.get(2013, 5, 5, 12, 30, 45)), which raised:

TypeError: Arrow.__init__() missing 1 required positional argument: 'day'

This is a real-world footgun for callers that pass an optional, possibly-None, timezone straight through as a kwarg (e.g. arrow.get(value, fmt, tzinfo=account.timezone) where account.timezone can be None).

Fix

Check for the key's presence rather than its value:

# tzinfo kwarg is not provided
if len(kwargs) == 1 and "tzinfo" not in kwargs:
    arg_count = 3

Now tzinfo=None behaves the same as omitting tzinfo entirely (defaults to UTC), while an explicit non-tzinfo single kwarg still correctly routes to the constructor path, and tzinfo=<value> still works as before.

Test plan

  • Added test_kwarg_tzinfo_none_with_string_and_format to tests/test_factory.py, asserting arrow.get(str, fmt, tzinfo=None) produces the same result as arrow.get(str, fmt) (UTC).
  • python -m pytest tests/test_factory.py -q → 49 passed, 1 skipped.
  • Manually verified before the fix this raised TypeError, and after the fix arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None), tzinfo='US/Pacific', and omitted-tzinfo all behave correctly.
  • python -m black --check arrow/factory.py tests/test_factory.py → clean.

The kwarg-count check in ArrowFactory.get() used 'tz is None' to
detect that only the tzinfo kwarg was passed, so it could fall back
to the 3+ positional-argument constructor path. This meant an
explicitly passed tzinfo=None (as opposed to omitting the kwarg
entirely) was misidentified, and arrow.get(<str>, <fmt>, tzinfo=None)
incorrectly routed to self.type(*args, **kwargs), raising a
confusing TypeError about a missing 'day' argument instead of
parsing the string as expected.

Check for the key's presence instead of its value.

Fixes arrow-py#1259
Copilot AI lite review requested due to automatic review settings August 20, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (dc73690).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1339   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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 this pull request may close these issues.

arrow.get() behaviour for tzinfo=None

2 participants