Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a timezone-related bug in the deadline check functionality by making the current time timezone-aware (UTC). The change ensures correct comparison between the current time and database-stored deadlines, which are timezone-aware datetime objects returned by PostgreSQL.
- Changed import from
from datetime import datetimetoimport datetimefor better namespace clarity - Updated
check_deadline()to usedatetime.datetime.now(datetime.timezone.utc)instead of naivedatetime.now()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def check_deadline(leaderboard: LeaderboardItem): | ||
| now = datetime.now() | ||
| now = datetime.datetime.now(datetime.timezone.utc) |
There was a problem hiding this comment.
The tests in test_check_deadline() use naive datetime objects (datetime.datetime.now() without timezone), but the production code now uses timezone-aware datetime objects (datetime.datetime.now(datetime.timezone.utc)). This mismatch means the tests are not accurately testing the actual behavior.
The tests should be updated to use timezone-aware datetime objects to match the production code:
def test_check_deadline():
# Test valid deadline (future)
future_deadline: LeaderboardItem = {
"deadline": datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1),
"name": "test",
}
submission.check_deadline(future_deadline) # Should not raise
# Test expired deadline
past_deadline: LeaderboardItem = {
"deadline": datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1),
"name": "test",
}
# ...Additionally, the mock in mock_backend fixture (line 30) should also use timezone-aware datetime.
No description provided.