Conversation
datetime.utcnow() is deprecated since Python 3.12 and is scheduled for removal. Replace all 19 call sites with a single featureflags.utils.utcnow() helper built on datetime.now(UTC). The helper drops the tzinfo, so it returns the same naive UTC value that datetime.utcnow() did. The TIMESTAMP columns hold naive values, and comparisons run against them, so keeping the result naive avoids "can't compare offset-naive and offset-aware datetimes". Re-enable the ruff rule DTZ003, which flags datetime.utcnow(), so the call cannot come back.
Flag and Value declared the columns as Column(default=utcnow()). The parentheses call the function once, while the module is imported, so every row a process writes carries the same timestamp: the moment the process started. _create_flag() and _create_value() never set these columns, so this default is what reaches the database, and created_timestamp is exposed through the GraphQL API. Pass the function itself so SQLAlchemy calls it per insert.
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.
🤖 Description written by an agent.
Two related changes, one commit each.
1. Use a
utcnow()helper instead ofdatetime.utcnow()datetime.utcnow()is deprecated since Python 3.12 and is scheduled for removal. All 19 call sites now go through a singlefeatureflags.utils.utcnow()helper built ondatetime.now(UTC).The helper drops the tzinfo, so it returns the same naive UTC value as before. The
TIMESTAMPcolumns hold naive values and are compared against, so keeping the result naive avoidscan't compare offset-naive and offset-aware datetimes.The ruff rule
DTZ003flagsdatetime.utcnow(). It was in theignorelist; this commit enables it again so the call cannot come back.No behaviour change.
2. Fix frozen
created_timestamp/reported_timestampdefaultsFlagandValuedeclare the column like this:The parentheses make Python call the function once, while the module is imported. Every row written by a process then carries the same timestamp — the moment the process started.
_create_flag()and_create_value()never set the column, so this default is what reaches the database, andcreated_timestampis exposed through the GraphQL API.Passing the function itself lets SQLAlchemy call it per insert.
featureflags/tests/test_models.pyis new and asserts the four column defaults are callable.Verification
lets test— all tests pass.ruff check featureflags— no new findings against the pre-change baseline.