Warn on cached lookups of guessed globally unique TZIDs - #1661
Warn on cached lookups of guessed globally unique TZIDs#1661codeAnqiang-ma wants to merge 1 commit into
Conversation
|
Profile summary: Full profile |
|
This pull request did not pass quality checks and AI use is suspected. Please review Contribute and make any necessary amendments. |
TZP.timezone() cached guessed timezones under the cleaned id, so only the first lookup of a globally unique TZID warned. Now guessed entries are remembered and cache hits warn too; this also fixes the order dependence of test_timezone_id_resolves in pytz-free runs. Fixes collective#1660 AI use: Claude (Fable 5) via Cursor drafted the fix and test; I reviewed, tested, and verified it. Co-authored-by: Cursor <cursoragent@cursor.com>
6417a6b to
0213619
Compare
Documentation build overview
3 files changed± 404.html± reference/api/icalendar.timezone.tzp.html± _modules/icalendar/timezone/tzp.html |
|
Amendments per the quality-check feedback: I shortened the commit message and the PR description, keeping the AI disclosure in the commit message and the change log entry per the Responsible AI use policy. The fix and its regression test are unchanged. The earlier Documentation and Read the Docs failures were transient network errors while provisioning the build environment; all checks pass after the re-run. |
|
Thanks for the PR! Is it normal practice to warn several times? |
|
To be clear for you: I did neither understand your issue and also not your PR description. But the code makes sense! Could you in future just write your own, small descriptions? |
Yes — the usual practice is to emit on every occurrence and let the user's warning filters decide what is shown, like
Fair point — I'll keep future descriptions short. |
lcampanella98
left a comment
There was a problem hiding this comment.
Nice PR.
One suggestion on the test below, and one question on scope.
This says Closes #1660, but the issue reports two problems and this fixes one. [testenv:nopytz] still inherits dependency_groups = test, which lists pytz>=2025.2, so the 3.10 (nopytz) job keeps running with pytz and would not catch a repeat of this. Fine with me to leave that fix out of this PR, but then better not to auto-close the issue in my opinion.
| tzid = "/mozilla.org/20070129_1/America/New_York" | ||
| with pytest.warns(GloballyUniqueTZIDGuessed): | ||
| first = tzp.timezone(tzid) | ||
| with pytest.warns(GloballyUniqueTZIDGuessed): | ||
| second = tzp.timezone(tzid) | ||
| assert first is second |
There was a problem hiding this comment.
I think it'd be good to pin the message as well which changed from using lookup_id to guessed_id which are different on cache hit
| tzid = "/mozilla.org/20070129_1/America/New_York" | |
| with pytest.warns(GloballyUniqueTZIDGuessed): | |
| first = tzp.timezone(tzid) | |
| with pytest.warns(GloballyUniqueTZIDGuessed): | |
| second = tzp.timezone(tzid) | |
| assert first is second | |
| tzid = "/mozilla.org/20070129_1/America/New_York" | |
| guess = "guessing it means 'America/New_York'" | |
| with pytest.warns(GloballyUniqueTZIDGuessed, match=guess): | |
| first = tzp.timezone(tzid) | |
| with pytest.warns(GloballyUniqueTZIDGuessed, match=guess): | |
| second = tzp.timezone(tzid) | |
| assert first is second |
Solaris-star
left a comment
There was a problem hiding this comment.
Verified the current head 0213619845d5ff2525de409d70dd40c0fe1d5f1f locally.
PYTHONPATH=src uv run --no-project --python 3.13 --with pytest --with python-dateutil --with tzdata --with typing-extensions --with pytz python -m pytest src/icalendar/tests/test_issue_313_globally_unique_tzid.py -q— 22 passed.- The same command without
--with pytz— 11 passed. git diff --check 0213619845d5ff2525de409d70dd40c0fe1d5f1f^ 0213619845d5ff2525de409d70dd40c0fe1d5f1f— clean.
The cache-warning fix and regression test behave correctly in both provider configurations. I did not run the full tox/docs matrix. The remaining merge blocker appears to be scope/issue linkage rather than this code path: #1660 also tracks the nopytz tox dependency problem, while this PR fixes the cache-warning behavior only. Changing Closes #1660 to a non-closing reference (and adjusting the news wording if needed) would align with the collaborator feedback.
|
@Solaris-star Thanks for your review and continuous engagement with the project!
So, how is that for you? |
|
Thanks for the reminder — noted! Let me condense my conclusion into an actionable single point: the code at head I re-verified the current head myself:
I did not run the full tox suite, docs build, or the full-matrix CI, so those checks should still be confirmed against remote CI. Going forward I'll keep reviews to short conclusions, blockers, and concrete next steps to avoid extra reading burden for contributors. |
|
@Solaris-star 谢谢您的回复!能否请您将其翻译成英语,并修改一下您的评论? Thank you for the response! Could you translate it to English and edit your comment, please? |
|
@codeAnqiang-ma your PR receives a lot of attention. Let us know how you would like to proceed. If you have any questions or if we can clarify sometjing, please let us know! |
stevepiercy
left a comment
There was a problem hiding this comment.
@codeAnqiang-ma would you please take a look at the feedback and respond in kind? This is nice work. Thank you!
| @@ -0,0 +1 @@ | |||
| Emit :class:`~icalendar.error.GloballyUniqueTZIDGuessed` on every lookup of a globally unique TZID (:rfc:`5545#section-3.2.19`), including lookups served from the TZID cache. Previously only the first lookup on a ``TZP`` instance warned: the guessed timezone was cached under the cleaned id, so repeated lookups returned silently, which also made ``test_timezone_id_resolves`` order-dependent and fail in pytz-free environments. Drafted with AI assistance; reproduced, reviewed, and verified by the author. @codeAnqiang-ma | |||
There was a problem hiding this comment.
Minor spelling tweak.
| Emit :class:`~icalendar.error.GloballyUniqueTZIDGuessed` on every lookup of a globally unique TZID (:rfc:`5545#section-3.2.19`), including lookups served from the TZID cache. Previously only the first lookup on a ``TZP`` instance warned: the guessed timezone was cached under the cleaned id, so repeated lookups returned silently, which also made ``test_timezone_id_resolves`` order-dependent and fail in pytz-free environments. Drafted with AI assistance; reproduced, reviewed, and verified by the author. @codeAnqiang-ma | |
| Emit :class:`~icalendar.error.GloballyUniqueTZIDGuessed` on every lookup of a globally unique TZID (:rfc:`5545#section-3.2.19`), including lookups served from the TZID cache. Previously only the first lookup on a ``TZP`` instance warned: the guessed timezone was cached under the cleaned ID, so repeated lookups returned silently, which also made ``test_timezone_id_resolves`` order-dependent and fail in pytz-free environments. Drafted with AI assistance; reproduced, reviewed, and verified by the author. @codeAnqiang-ma |
Linked issue
Description
Guessed timezones were cached under the cleaned TZID, so only the first lookup of a globally unique TZID warned; later lookups hit the cache and stayed silent. The cache now remembers guesses and warns on hits too. It also fixes a test-order dependence in pytz-free runs (see the linked issue). A regression test fails before and passes after.
Checklist
Additional information
AI disclosure: drafted with AI (Claude via Cursor); reproduced, reviewed, and verified by me.