Skip to content

Replace datetime.utcnow() with datetime.now(timezone.utc) - #6880

Open
theoniko wants to merge 1 commit into
mozilla:masterfrom
theoniko:fix-5367-replace-datetime.utcnow-with-datetime.now-timezone.utc
Open

theoniko wants to merge 1 commit into
mozilla:masterfrom
theoniko:fix-5367-replace-datetime.utcnow-with-datetime.now-timezone.utc

Conversation

@theoniko

Copy link
Copy Markdown
Contributor

Fixes #5367

@theoniko
theoniko force-pushed the fix-5367-replace-datetime.utcnow-with-datetime.now-timezone.utc branch 3 times, most recently from 084467f to bf54046 Compare September 19, 2026 14:02
@theoniko
theoniko force-pushed the fix-5367-replace-datetime.utcnow-with-datetime.now-timezone.utc branch from bf54046 to 65fe24e Compare September 19, 2026 14:50
@theoniko
theoniko marked this pull request as ready for review September 19, 2026 17:13
@theoniko
theoniko requested a review from a team as a code owner September 19, 2026 17:13

@suhaibmujahid suhaibmujahid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good to me in general, just simple changes.

Comment thread bugbug/models/backout.py
Comment on lines 125 to +129
pushdate = dateutil.parser.parse(commit_data["pushdate"])
if pushdate.tzinfo is None:
pushdate = pushdate.replace(tzinfo=tz.UTC)
else:
pushdate = pushdate.astimezone(tz.UTC)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified:

Suggested change
pushdate = dateutil.parser.parse(commit_data["pushdate"])
if pushdate.tzinfo is None:
pushdate = pushdate.replace(tzinfo=tz.UTC)
else:
pushdate = pushdate.astimezone(tz.UTC)
pushdate = datetime.fromisoformat(commit_data["pushdate"])
pushdate = pushdate.replace(tzinfo=pushdate.tzinfo or timezone.UTC)

Comment on lines -76 to +90
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
server_default=func.now(), server_onupdate=func.now()
DateTime(timezone=True),
nullable=False,
server_default=func.now(),
server_onupdate=func.now(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems out of the scope of this PR.

This branch has not been deployed

No deployments
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.

Replace datetime.utcnow() with datetime.now(timezone.utc)

2 participants