chore: Replace pytz with zoneinfo for UTC handling - Part 1 (#37523)

First PR to replace pytz with zoneinfo for UTC handling across codebase.

This PR migrates all UTC timezone handling from pytz to Python’s standard
library zoneinfo. The pytz library is now deprecated, and its documentation
recommends using zoneinfo for all new code. This update modernizes our
codebase, removes legacy pytz usage, and ensures compatibility with
current best practices for timezone management in Python 3.9+. No functional
changes to timezone logic - just a direct replacement for UTC handling.

https://github.com/openedx/edx-platform/issues/33980
This commit is contained in:
Tarun Tak
2025-10-29 01:53:22 +05:30
committed by GitHub
parent 6deb4f8d05
commit 18d5abb2f6
70 changed files with 263 additions and 234 deletions

View File

@@ -11,7 +11,7 @@ from completion import handlers
from completion.models import BlockCompletion
from completion.test_utils import CompletionSetUpMixin
from django.test import TestCase
from pytz import utc
from zoneinfo import ZoneInfo
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock
@@ -66,7 +66,7 @@ class ScorableCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
usage_id=str(block_key),
weighted_earned=0.0,
weighted_possible=3.0,
modified=datetime.utcnow().replace(tzinfo=utc),
modified=datetime.utcnow().replace(tzinfo=ZoneInfo("UTC")),
score_db_table='submissions',
**params
)
@@ -127,7 +127,7 @@ class ScorableCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
usage_id=str(self.block_key),
weighted_earned=0.0,
weighted_possible=3.0,
modified=datetime.utcnow().replace(tzinfo=utc),
modified=datetime.utcnow().replace(tzinfo=ZoneInfo("UTC")),
score_db_table='submissions',
)
mock_handler.assert_called()
@@ -153,7 +153,7 @@ class DisabledCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
usage_id=str(self.block_key),
weighted_earned=0.0,
weighted_possible=3.0,
modified=datetime.utcnow().replace(tzinfo=utc),
modified=datetime.utcnow().replace(tzinfo=ZoneInfo("UTC")),
score_db_table='submissions',
)
with pytest.raises(BlockCompletion.DoesNotExist):