Repository navigation
Use the site date for "today", not the UTC date (#1479) - #1505
Conversation
Freeze the clock at 04:00 UTC on 4 Mar 2031 (20:00 on 3 Mar Pacific) and check each decision that reads the UTC date as "today": admin advisor/mentor choices, Person.is_alumni_member, bio_datetime_modified, the Data Health CSV filename, and time on project for ongoing roles. Add a guard against now().date() in the shipped packages, and switch test_person_save's two assertions to timezone.localdate(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
timezone.now().date() is the UTC date, a day ahead from 16:00 (17:00 in summer) Pacific. Switch every such site to timezone.localdate(): admin advisor and mentor choices, Person.is_alumni_member, bio_datetime_modified, the Data Health CSV filename, and the ongoing role duration in Project.get_people. Person.get_total_time_on_project coalesced with timezone.now(), a datetime; it now uses the site date too. video.py and ml_utils.py used naive local now().date(), which was already right; they move to timezone.localdate() so the guard needs no allowlist. Person.is_alumni_member also goes back to end_date < today, the rule before #1346, so a member is not counted as alumni on their last day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonfroehlich
left a comment
There was a problem hiding this comment.
Review of head b155889
No blocking and no should-fix findings. Every claim in the PR body that I checked held. Five nits, all in website/tests/test_site_date.py; none needs to hold the merge.
Local runs used Python 3.13.1 in the project's Docker image (stale against the current pins) with an isolated Postgres 16. I did not check the Actions run.
Claims re-derived
| Claim | Result |
|---|---|
| New tests fail first on e6dba8c (tests only) | Confirmed: 16 tests, 12 failures, same assertion messages as the PR body |
| The guard hit exactly 9 lines on base | Confirmed, same 9 file:line entries |
| Full suite with the fix: 1233 tests, 2 failures, 34 skipped | Confirmed exactly |
| The 2 failures are not from this change | Confirmed: both fail on a643f99 with the same image |
Person.is_alumni_member used end_date__lt=timezone.now() before fb356b7 |
Confirmed from that commit's diff; it introduced <= and the comment wrongly saying the two match |
Position.is_alumni_member uses < |
Confirmed |
date.today() is already the site date |
Confirmed: after django.setup(), TZ is America/Los_Angeles and naive now is 8 h behind UTC |
get_people and get_total_time_on_project have no callers outside tests |
Confirmed by grep |
The video.py and ml_utils.py conversions are safe |
Confirmed: breaking either line makes existing tests error, so the new imports are exercised at runtime |
Missed "today" call sites: none found
I grepped the shipped Python for now(, today(, utcnow, localdate, localtime, .date() and the DB-side forms (Now(), CURRENT_DATE, TruncDate, __date), and the templates for {% now %} and timesince. No now().date() remains, what is left matches the PR's "left alone" list, and there is no DB-side "now".
Mutation results
Each call site was reverted one at a time and the new tests run.
| Mutation | Killed by |
|---|---|
admin/utils.py:91 back to now().date() |
both professor tests, guard |
admin/utils.py:180 |
both mentor tests, guard |
registry.py:109 |
CSV filename test, guard |
person.py:289 to now().date() |
total-time test, guard |
person.py:289 to the original timezone.now() datetime |
total-time test only |
person.py:430 (alumni) to now().date() |
ending-today test, guard |
person.py:726, :728 (bio stamp) |
the matching bio test each, guard |
person.py:433 < to <= |
ending-today test |
project.py:833 |
get_people test, guard |
video.py:44, ml_utils.py:285 to naive now().date() |
guard only, as the PR says |
Guard: parents[2] to parents[1] |
test_every_shipped_root_exists |
Guard: rglob("*.py") to rglob("*.pyx") |
survived (nit 1) |
Guard: "website" dropped from SHIPPED_ROOTS |
survived (nit 1) |
Findings
- Nit: the guard can pass vacuously. Nothing checks that the scan reads any file or that the root list is complete. Changing
rglob("*.py")torglob("*.pyx"), or deleting"website"fromSHIPPED_ROOTS, leaves all 21 tests green. Suggested fix: assert that_shipped_python_files()yields a known file such aswebsite/models/person.py. - Nit:
NOW_DATE_REmissesnow(<args>).date().datetime.now(timezone.utc).date()is the UTC date written explicitly, and it passes the guard. No such call exists today. Suggested fix:now\([^)]*\)\s*\.date\(\s*\), which should add no hits on the current tree (not run). - Nit: the guard also matches comments and docstrings. A line like
# never timezone.now().date()in shipped code would turn it red. None exists today. A sentence in the failure message would do. - Nit: the module docstring is out of date after the fix. It says
video.pyandml_utils.pyhave no frozen test because the patch can't freeze them. That was true of the old code; both now calltimezone.localdate()and can be frozen (a video dated 7 days before the frozen site date reports exactly 7.0 days). Suggested fix: reword to say there was no way to fail first, and optionally add one frozenget_age_in_mstest. - Nit: "current" should be "default" time zone in the
DateFieldPrepTestsdocstring.DateField.to_pythonusestimezone.get_default_timezone(). The assertion is right, and nothing in the repo activates another zone, so there is no behaviour effect.
On decision 1 (< in Person.is_alumni_member): the history supports it and I agree with it. Note that after this PR the ending-today test is the one guarding both the operator and the date source; the ending-tomorrow test only fails for the old <=-plus-UTC combination.
Second review: Gemini 4 Neon (xhigh) (gemini-4-neon-xhigh)
Four findings, each tested the same way as my own.
| # | Finding | Severity | Verdict | Reason |
|---|---|---|---|---|
| 1 | _now_date_lines runs a line regex over comments, docstrings and strings |
nit | Confirmed | Same as my finding 3: the pattern matches a comment that names the banned form. Nothing is red today. |
| 2 | NOW_DATE_RE only matches zero-argument now() |
nit | Confirmed | Same as my finding 2: no match for datetime.now(timezone.utc).date() or the tz= form. |
| 3 | The module docstring falsely says video.py and ml_utils.py can't be frozen, leaving them without frozen tests |
nit | Partly valid | The docstring is right about the old code and misleading about the new (my finding 4). The "regression goes uncaught" part is weaker than stated: a revert to date.today() is not a bug, and existing tests already execute both lines. |
| 4 | DateFieldPrepTests says the conversion uses the current time zone; Django uses the default one |
nit | Confirmed | Checked against Django's source, and under timezone.override the two do diverge. Wording only, since nothing here activates a zone (my finding 5). |
no follow-up was needed (no blocking or should-fix finding rejected). The script excluded no files from the diff it sent.
🤖 Generated with Claude Code — review, triage and verdicts by Fable 5.2, claude-fable-5-2; second-review findings by gemini-4-neon-xhigh via Google Antigravity CLI
- Guard: assert the scan reads known shipped files, so a broken glob or a dropped root can't pass vacuously. - Guard regex: match now(<args>).date() too, e.g. datetime.now(timezone.utc).date(); self-test covers it. - Guard docstring and failure message: a hit in a comment counts too. - Module docstring: video.py and ml_utils.py could not fail first, but can be frozen now; add a frozen Video.get_age_in_ms test. - DateFieldPrepTests: default time zone, not current. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fix round 1 for review #1505 (review). All five nits are fixed in fa4c405 (one commit, test file only). I reproduced each finding before fixing it, and re-ran the module (18 tests, OK) in the project's Docker image, Python 3.13.1.
🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5 |
jonfroehlich
left a comment
There was a problem hiding this comment.
Review 2 of head fa4c405
This review covers b155889..fa4c405: one commit, website/tests/test_site_date.py only (+30/-6).
No blocking and no should-fix findings. All five nits from review 1 are closed, and the claims in the fix answers that I checked held. Two new nits, both about what the guard still does not cover; neither needs to hold the merge.
Local runs used Python 3.13.1 in the project's Docker image (stale against the current pins) with an isolated Postgres 16.
Review 1 findings
| # | Review 1 nit | Status | How checked |
|---|---|---|---|
| 1 | Guard can pass vacuously | Closed | rglob("*.pyx") and dropping "website" from SHIPPED_ROOTS now both fail test_scan_reads_known_shipped_files |
| 2 | NOW_DATE_RE misses now(<args>).date() |
Closed for flat arguments (see nit A) | Reverting the regex fails the detector self-test; the widened pattern has no hits on the shipped tree |
| 3 | Guard matches comments and docstrings | Closed, as suggested | Now stated in the class docstring and the failure message (read only) |
| 4 | Module docstring out of date for video.py / ml_utils.py |
Closed | Docstring reworded; the new test_video_age_counts_from_site_date is mutation-sensitive (below) |
| 5 | "current" vs "default" time zone | Closed | Docstring now says "the default time zone (TIME_ZONE)" |
Full suite
1235 tests, 2 failures, 34 skipped: review 1's 1233 plus the 2 new tests. The 2 failures are the same two that review 1 showed failing on base with this image (test_hide_elements_includes_installed_toolbar_host and test_cleaner_kwargs_match_snapshot); I did not re-run them on base this round. The module alone runs 18 tests, OK. The Actions checks on this head (test, a11y, e2e) are green; I read their status, not their logs.
Mutation results
Each mutation was applied alone and the module run.
| Mutation | Result |
|---|---|
Regex back to zero-argument now\(\s*\) |
Killed (detector self-test) |
Regex requires arguments ([^)]+) |
Killed (detector self-test) |
rglob("*.py") to "*.pyx" |
Killed (scan test) |
Drop "website", "makeabilitylab" or "manage.py" from SHIPPED_ROOTS |
Killed each time (scan test) |
Drop "scripts" or "image_cropping" from SHIPPED_ROOTS |
Survived (nit B) |
SKIP_DIRS loses "tests" |
Killed (scan test and guard) |
SKIP_DIRS loses "migrations" |
Survived (nit B) |
| Skip check disabled | Killed (scan test and guard) |
get_age_in_ms to timezone.now().date() |
Killed (video test and guard) |
get_age_in_ms to naive datetime.now().date() |
Killed (video test and guard) |
get_age_in_ms to date.today() |
Killed (video test) |
get_age_in_ms factor 1000 to 1 |
Killed (video test) |
Findings
A. Nit: NOW_DATE_RE misses now() when its argument contains a call. [^)]* stops at the first ), so datetime.now(ZoneInfo("UTC")).date() and datetime.now(pytz.timezone("UTC")).date() pass the guard. These are common ways to write the UTC date explicitly, which is the case review 1's nit 2 was about. Reproduce: re.search(r"now\([^)]*\)\s*\.date\(\s*\)", 'x = datetime.now(ZoneInfo("UTC")).date()') returns None. No such call exists in shipped code today (a greedy grep finds none). Possible fix: now\(.*?\)\s*\.date\(\s*\) with one more self-test line. That pattern matches the ZoneInfo form and leaves timezone.now() and timezone.localdate() alone in a quick check; I did not run it over the tree. Listing the case under the docstring's "Limits" would also do.
B. Nit: the scan test pins 3 of the 7 roots and half of SKIP_DIRS. Dropping "scripts" or "image_cropping" from SHIPPED_ROOTS leaves all 18 tests green (the other two unpinned roots, sortedm2m_filter_horizontal_widget and ckeditor_uploader, follow by the same logic; not run). Removing "migrations" from SKIP_DIRS also survives, because website/migrations/ is gitignored and absent in a fresh checkout and in CI. The impact is small: the mutation review 1 asked about is killed, and the four unpinned roots hold 10 of the 240 tracked .py files. Possible fix: assert one known file per root, or leave it.
Second review: Gemini 4 Neon (xhigh) (gemini-4-neon-xhigh)
Three findings, each tested the same way as my own.
| # | Finding | Severity | Verdict | Reason |
|---|---|---|---|---|
| 1 | [^)]* in NOW_DATE_RE fails on a timezone argument with nested parentheses |
nit | Confirmed | Same as my nit A. All four of its examples (ZoneInfo("UTC"), pytz.timezone("UTC"), datetime.timezone(timedelta(0)), timezone.get_fixed_timezone(0)) return no match. Nothing in shipped code uses the form today. |
| 2 | The "/tests/" / "/migrations/" substring check misses top-level directories and ignores the rest of SKIP_DIRS |
nit | Partly valid | True that the check repeats two names instead of using SKIP_DIRS, so __pycache__ is not asserted. The top-level case can't happen as written: every scanned path starts with a root name from SHIPPED_ROOTS, so a skipped directory is never the first path part. No .py file sits under a __pycache__ in the tree. |
| 3 | test_scan_reads_known_shipped_files checks files from only 3 of the 7 roots |
nit | Confirmed | Same as my nit B: dropping "scripts" or "image_cropping" survives. |
No follow-up was needed (no blocking or should-fix finding rejected). The script excluded no files from the diff it sent.
🤖 Generated with Claude Code — review, triage and verdicts by Fable 5.2, claude-fable-5-2; second-review findings by gemini-4-neon-xhigh via Google Antigravity CLI
- NOW_DATE_RE allows balanced parentheses two levels deep in now(...),
so now(ZoneInfo("UTC")).date() and now(timezone(timedelta(0))).date()
are caught, while a later unrelated .date() on the line is not.
- The scan test pins one known file in every shipped root and checks
the skip rule against SKIP_DIRS instead of two hard-coded names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fix round 2 for review #1505 (review). All fixes are in 3874c1d, which touches only the test file. I reproduced each finding first. After the fix, A / Gemini 1. B / Gemini 3. The scan test pins only 3 of the 7 roots. Fixed (3874c1d). It now pins one known file per root: B, Gemini 2. The skip check repeats two names instead of using 🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5 |
Closing check: nothing foundRead at head 3874c1d: the whole PR ( FindingsNone blocking or should-fix. Disagreed, not closedNone. Neither review (Gemini's findings included) raised a blocking or should-fix finding. The one point the answers disagreed with, pinning What was checked
Not blocking, for whoever merges: the PR body's test counts (11 behaviour tests, 1233 in the suite) describe the first head; two tests were added in fa4c405, so the suite is now 1235. 🤖 Generated with Claude Code — Fable 5.2, claude-fable-5-2 |
Closes #1479.
"Today" is now the site's date (
timezone.localdate()) everywhere shipped code usedtimezone.now().date(), the UTC date, which is already tomorrow from 16:00 (17:00 in summer) Pacific. Implements the agreed plan in #1479 (comment).Call sites changed
admin/utils.pyget_active_professors_querysetadmin/utils.pyget_active_mentors_querysetmodels/person.pyPerson.is_alumni_membermodels/person.pyPerson.save()(2 lines)bio_datetime_modified("Bio last updated", sitemaplastmod) stamped a day aheadadmin/data_health/registry.pymodels/project.pyProject.get_peoplemodels/person.pyget_total_time_on_projecttimezone.now(), a datetime: 3 days 4 h for a role 2 site-days old. NowValue(timezone.localdate(), output_field=DateField())models/video.pyget_age_in_ms,utils/ml_utils.pychoose_banners_helpernow().date()was already the site date); converted so the guard needs no allowlist. Unuseddatetimeimports droppedAlso:
test_person_save.py's twobio_datetime_modifiedassertions now compare withtimezone.localdate()(they would otherwise fail between 00:00 and 08:00 UTC), andCLAUDE.mdgets a coding-convention line: "today" istimezone.localdate(), nevertimezone.now().date().Left alone (on purpose)
date.today()sites (position and project-role models, views, data-health checks,news.pydefault): Django setsTZfromTIME_ZONE, so they already give the site date.sponsor_admin.pyend_date__gt=timezone.now(): Django converts an aware datetime to the site date for aDateFieldlookup, so it is correct. A new control test pins that conversion.modifyprojectpeople.py(naive local, legacy), and real timestamps (banner_admin.py,models/banner.py,backup_status.py,schema_report.py).New tests:
website/tests/test_site_date.pyClock frozen at 04:00 UTC on 4 Mar 2031 (20:00 on 3 Mar Pacific) with the repo's existing
mock.patch("django.utils.timezone.now")pattern;setUpasserts the site and UTC dates differ.DateField().get_prep_value(aware datetime)gives the site date.SimpleTestCase) that fails withfile:lineon anynow().date()in the shipped packages only (website,makeabilitylab,image_cropping,sortedm2m_filter_horizontal_widget,ckeditor_uploader,scripts,manage.py; skippingtestsandmigrations), plus a detector self-test and a check that every listed root exists. Its docstring states its limits: it misses a split form liken = timezone.now(); n.date(), and a new top-level package must be added to the list.Failing first
Commit e6dba8c (tests only) against the unchanged code, Python 3.13.1 in the project's Docker image:
The guard listed exactly the 9 lines changed here:
admin/utils.py:91,:180,models/person.py:425,:721,:723,models/video.py:45,models/project.py:833,utils/ml_utils.py:285,admin/data_health/registry.py:109.Full suite with the fix
python manage.py test website --settings=makeabilitylab.settings_test, Python 3.13.1 (project Docker image): 1233 tests, 2 failures, 34 skipped. The two failures (test_news_prose_editor...test_cleaner_kwargs_match_snapshot,test_pa11y_ci_config...test_hide_elements_includes_installed_toolbar_host) fail identically on untouched master a643f99 with the same image, which is stale against the pins bumped in #1497 and #1499. CI, which builds fromrequirements.txt, is the gate.Decisions (PROVISIONAL, all reversible at review)
Person.is_alumni_membernow usesend_date < todayinstead of<=. This is a behaviour change: on a member's last day they no longer count as alumni (before, they counted as both current and alumni). It restores the rule from before Admin changelist audit: make all listing pages manageable (perf + findability) #1346 (end_date__lt=timezone.now(), compared as the site date) and matchesPosition.is_alumni_member. The method's comment, which wrongly said<=matched the old filter, is rewritten. To keep<=instead: revert that operator and droptest_member_position_ending_today_is_not_alumni.date.today()sites left as they are; no follow-up filed.video.pyandml_utils.pyconverted (no behaviour change).get_total_time_on_projectincluded.tests/base.pyyet.CLAUDE.mdconvention line added.No model, template or UI change, so no screenshots or Pa11y run.
🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5