Repository navigation
Read a naive datetime in older_than as local time - #4220
Open
Rahul-cs50 wants to merge 1 commit into
Open
Rahul-cs50 wants to merge 1 commit into
Rahul-cs50 wants to merge 1 commit into
Conversation
expire_snapshots().older_than() converted its cutoff with datetime_to_millis, which reads a naive datetime as UTC. The docs call it with datetime.now() - timedelta(...), a naive local time, so east of UTC the cutoff landed later and expired snapshots that should be kept, and west of UTC it landed earlier. A naive datetime is now read as local time, as datetime.timestamp() does; an aware one is unchanged. Closes apache#4182
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4182
Rationale for this change
expire_snapshots().older_than(dt)converts the cutoff withdatetime_to_millis, which reads a naive datetime as UTC. The docs call it asolder_than(datetime.now() - timedelta(days=3)), anddatetime.now()is a naive local time, so east of UTC the cutoff lands later than asked (in Tokyo,datetime.now() - timedelta(hours=1)expires snapshots that are seconds old) and west of UTC it lands earlier.older_than()now reads a naive datetime as local time, asdatetime.timestamp()does, by callingastimezone()on it before the conversion. An aware datetime is handled as before.datetime_to_millisitself is unchanged, since a naive value there means UTC for timestamp columns.Are these changes tested?
Yes.
test_expire_snapshots_older_than_reads_naive_datetime_as_local_timeintests/table/test_expire_snapshots.pysetsTZtoAsia/Tokyoand checks that a naive cutoff one minute before a snapshot keeps it and one minute after expires it. It fails onmainand passes with this change (it is skipped wheretime.tzsetis unavailable). The issue's script now keeps all three snapshots underAsia/Tokyo,America/Los_AngelesandUTC.tests/tableandtests/utils: 768 passed.ruff checkandruff format --checkare clean.Are there any user-facing changes?
older_than()with a naive datetime now uses the local time zone instead of UTC. Callers who passed naive UTC datetimes on purpose should pass an aware one (datetime.now(timezone.utc)).