fix(backend): use timezone.now() for licensing and analytics timestamps - #1002
Open
omlahore wants to merge 1 commit into
Open
fix(backend): use timezone.now() for licensing and analytics timestamps#1002omlahore wants to merge 1 commit into
omlahore wants to merge 1 commit into
Conversation
issued_at was written to a DateTimeField as a naive server-local datetime under USE_TZ, the license expiry check compared a server-local date against the license date, and the decrypt-count chart window started from a naive now(). Matches the timezone.now() used in the other 143 call sites.
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.
Follow-up to #972, same class of bug in three more places.
USE_TZ = TrueandTIME_ZONE = "UTC", and the backend already usestimezone.now()in 143 call sites against 7 naive ones. These are three of the seven.1.
ee/licensing/utils.py:144— naive datetime into a DateTimeFieldActivatedPhaseLicense.issued_atis aDateTimeFieldand this reaches it throughobjects.create(**fields). UnderUSE_TZDjango warns and interprets the value as UTC, but it was produced in server-local time, so a non-UTC host stores anissued_atthat is wrong by its offset. This is exactly what #972 fixed for token expiry.activated_aton the same dict is changed for consistency only. That column isauto_now_add=True, so Django overwrites whatever is passed and the current value is not a live bug.2.
ee/licensing/verifier.py:33— license expiry judged in server-local timeexpires_atis parsed from the signed license as a plain date, so this compares it against the server's local date. Enterprise licences expire early on any host east of UTC.At
2026-09-02 20:30 UTC, for a licence withexpires_at = 2026-09-02:datetime.now().date()timezone.now().date()The licence dies up to a day early depending on where the instance runs.
3.
backend/schema.py:1408— analytics window anchored to local timeend_dateand thestart_datederived from it are used to bucket decrypt counts against timezone-aware rows, so the chart window is shifted by the host's UTC offset.Deliberately not touched
api/views/kms.py:28andbackend/schema.py:1122both dodatetime.now().timestamp() * 1000.timestamp()interprets a naive value as local time, so the epoch value is correct and changing these would be churn.ee/integrations/secrets/dynamic/aws/utils.py:210usesdatetime.utcnow()for AWS IAM tag values. Nothing reads those tags back, so it is a cosmetic and deprecation issue rather than a defect. Can send it separately if you want it.Verification
pytest tests/passes locally: 1503 passed. The suite does not need Postgres, so I can run it for backend changes from now on rather than leaving them unverified as I did on #972.