routes_shared calls ZoneInfo without a fallback and reports the failure as an invalid timestamp
Summary
routes_shared calls ZoneInfo('America/New_York') at three places with no guard and no fallback. On a host without a tz database the module still imports, but is_market_open('us-stock') raises, and validate_executed_at catches the failure in a broad except Exception and returns it as Invalid executed_at. Every realtime trade is then rejected with 400 and a reason that blames the caller's timestamp, including for crypto, where no timezone is involved.
Where
| Line | Call |
|---|---|
routes_shared.py:12 |
from zoneinfo import ZoneInfo |
routes_shared.py:642 |
is_us_market_open |
routes_shared.py:664 |
validate_executed_at, the 'now' branch |
routes_shared.py:689 |
validate_executed_at, for every market |
Two details make the failure reach callers that have nothing to do with US market hours:
routes_shared.py:689 converts to Eastern time for every market:
dt_et = dt_utc.astimezone(ZoneInfo('America/New_York'))
day = dt_et.weekday()
time_in_minutes = dt_et.hour * 60 + dt_et.minute
if normalized_market == 'us-stock':dt_et, day and time_in_minutes are only read inside the us-stock branch below.
routes_shared.py:704-705 turns anything that goes wrong into a verdict about the input:
except Exception as exc:
return False, f'Invalid executed_at: {exc}'Environment
| Commit | d03ff6c |
| Python | 3.14.7 |
| OS | macOS 26.6.2, arm64 |
Reproduction
In a subprocess with tzdata blocked through a meta_path finder and an empty tzpath, after asserting that ZoneInfo('America/New_York') does raise:
import routes_shared: ok
is_us_market_open() -> ZoneInfoNotFoundError: 'No time zone found with key America/New_York'
is_market_open('us-stock') -> ZoneInfoNotFoundError: 'No time zone found with key America/New_York'
is_market_open('crypto') -> True
validate_executed_at(..., 'us-stock') -> (False, "Invalid executed_at: 'No time zone found with key America/New_York'")
validate_executed_at(..., 'crypto') -> (False, "Invalid executed_at: 'No time zone found with key America/New_York'")
for comparison, price_fetcher on the same host:
import price_fetcher -> ZoneInfoNotFoundError: 'No time zone found with key America/New_York'The timestamp passed in was 2026-05-19T14:00:00Z, which is valid. is_market_open('crypto') returns correctly because it leaves before reaching the conversion, but validate_executed_at does not.
Scope
routes_signals.py:174 calls is_market_open, and :200 calls validate_executed_at, both on the realtime trade path. With no tz database the first raises and the second rejects, so no trade can be recorded in any market. No test covers either function.
Relation to #293
Same missing tz database, different failure mode, and it is worth keeping them apart:
price_fetcher.py |
routes_shared.py |
|
|---|---|---|
| Guard | except ImportError, which does not catch ZoneInfoNotFoundError |
none |
| Fallback | a fixed -5 offset |
none |
| Failure | the module does not import | the module imports, calls raise later |
PR #297 fixes the guard in price_fetcher and deliberately does not touch this file.
Not verified
- Not reproduced on a real tzdata-less host such as Alpine or Windows without the
tzdatapackage. The subprocess reproduces the condition by emptying the tzpath and blocking the package. - Whether the operators run such a host is unknown;
service/requirements.txtdoes not pintzdata. - The broad
except Exceptionat:704is reported here because it is what carries this particular failure to the caller. How many other failures it currently hides was not measured.
Source: HKUDS/AI-Trader