Skip to content

Commit fdb0127

Browse files
committed
BUG#35832148: Fix Django timezone.utc deprecation warning
The use of the django.utils.timezone.utc alias triggers a deprecation warning from Django, when Python warnings are enable. This patch fixes this issue by using the Python built-in datetime.timezone.utc in the Connecton/Python Django operations module. Change-Id: If76904b41966979d54efd6135708b87942ed21e4
1 parent c798c5c commit fdb0127

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ v8.3.0
1717
- WL#15942: Improve type hints and standardize byte type handling
1818
- WL#15523: Support Python DB API asynchronous execution
1919
- BUG#35912790: Binary strings are converted when using prepared statements
20+
- BUG#35832148: Fix Django timezone.utc deprecation warning
2021
- BUG#35710145: Bad MySQLCursor.statement and result when query text contains code comments
2122

2223
v8.2.0

lib/mysql/connector/django/operations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
"""Database Operations."""
3232

33-
from datetime import datetime, time
33+
from datetime import datetime, time, timezone
3434
from typing import Optional
3535

3636
from django.conf import settings
3737
from django.db.backends.mysql.operations import (
3838
DatabaseOperations as MySQLDatabaseOperations,
3939
)
40-
from django.utils import timezone
40+
from django.utils import timezone as django_timezone
4141

4242
try:
4343
from _mysql_connector import datetime_to_mysql, time_to_mysql
@@ -74,7 +74,7 @@ def value_to_db_datetime(self, value: Optional[datetime]) -> Optional[bytes]:
7474
if value is None:
7575
return ans
7676
# MySQL doesn't support tz-aware times
77-
if timezone.is_aware(value):
77+
if django_timezone.is_aware(value):
7878
if settings.USE_TZ:
7979
value = value.astimezone(timezone.utc).replace(tzinfo=None)
8080
else:
@@ -96,7 +96,7 @@ def value_to_db_time(self, value: Optional[time]) -> Optional[bytes]:
9696
return None
9797

9898
# MySQL doesn't support tz-aware times
99-
if timezone.is_aware(value):
99+
if django_timezone.is_aware(value):
100100
raise ValueError("MySQL backend does not support timezone-aware times")
101101

102102
if not self.connection.use_pure:

0 commit comments

Comments
 (0)