Skip to content

Replace deprecated datetime.utcnow() and fix frozen timestamp defaults - #80

Open
hyzyla wants to merge 2 commits into
evo-company:mainfrom
hyzyla:use-utcnow-helper
Open

hyzyla wants to merge 2 commits into
evo-company:mainfrom
hyzyla:use-utcnow-helper

Conversation

@hyzyla

@hyzyla hyzyla commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🤖 Description written by an agent.

Two related changes, one commit each.

1. Use a utcnow() helper instead of datetime.utcnow()

datetime.utcnow() is deprecated since Python 3.12 and is scheduled for removal. All 19 call sites now go through a single featureflags.utils.utcnow() helper built on datetime.now(UTC).

The helper drops the tzinfo, so it returns the same naive UTC value as before. The TIMESTAMP columns hold naive values and are compared against, so keeping the result naive avoids can't compare offset-naive and offset-aware datetimes.

The ruff rule DTZ003 flags datetime.utcnow(). It was in the ignore list; this commit enables it again so the call cannot come back.

No behaviour change.

2. Fix frozen created_timestamp / reported_timestamp defaults

Flag and Value declare the column like this:

created_timestamp = Column(TIMESTAMP, default=utcnow(), nullable=True)

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, and created_timestamp is exposed through the GraphQL API.

Passing the function itself lets SQLAlchemy call it per insert.

featureflags/tests/test_models.py is 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.

hyzyla added 2 commits August 27, 2026 14:43
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant