Time-only parsing during a repeated DST hour raises uncaught AmbiguousTimeError

オープン 初心者向け
#1,617 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend, testing

調査の方向性

まず dateparser/parser.py の _correct_for_time_frame を読み、特に tz.utcoffset() の呼び出しと例外処理を確認してください。提供されたスクリプトで、繰り返される時刻 1:30am のケースを使って問題を再現し、前後の時刻と比較してください。パーサーがタイムゾーンのポリシーに従うか、AmbiguousTimeError を漏らさずに None を返せば完了です。このケースに絞ったテストを追加するか、実行してください。

索引モデルが issue の本文から書いたものです。

説明

Hullo folks,

I'm doing some research for Tessl Code Review and we ran it against your repo. It flagged a potential issue, and I figured it made sense to share it with you:

Parsing a time during the repeated daylight-saving hour raises pytz.AmbiguousTimeError out of dateparser.parse() when using an aware RELATIVE_BASE and PREFER_DATES_FROM="past".

The ambiguity is real, but an ordinary time string currently escapes the parser's handling as an uncaught exception, unlike adjacent times.

from datetime import datetime
import dateparser
import pytz

settings = {
    "TIMEZONE": "America/Los_Angeles",
    "PREFER_DATES_FROM": "past",
    "RELATIVE_BASE": pytz.timezone("America/Los_Angeles").localize(
        datetime(2020, 11, 1, 12)
    ),
}

for time in ("0:30am", "1:30am", "2:30am"):
    try:
        print(time, dateparser.parse(time, settings=settings))
    except Exception as error:
        print(time, type(error).__name__, str(error))

Actual output:

0:30am 2020-11-01 00:30:00
1:30am AmbiguousTimeError 2020-11-01 01:30:00
2:30am 2020-11-01 02:30:00

Expected: handle the repeated hour according to the parser's timezone policy, or return None if it cannot be resolved, rather than leaking this exception.

The offset lookup in _correct_for_time_frame calls tz.utcoffset() with a naive wall time and catches UnknownTimeZoneError and NonExistentTimeError, but not AmbiguousTimeError. This is a different failure from the aware-datetime ValueError handled by #1362.

I ran this focused reproduction against current source ce8c4390dad4629daa2f154e7303052f9d88daec on macOS, Python 3.14.2, pytz 2026.6. No production data or full test suite was used; no patch is included.

Full transparency: I work at Tessl, and we've spotted that using Tessl Code Review - using repository-level context and specific review lenses that improve over time through feedback. That’s how this finding surfaced.

We’re just getting started and want to offer the tool free to open-source projects. If this is useful, happy to give you access.

Baptiste

主要言語
Python
スター
2.9k
フォーク
545
平均マージ
2日 4時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scrapinghub/dateparser のほかの issue

scrapinghub/dateparser の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。