Bug #112366 mysql-connector-python is triggering a Django deprecation warning
Submitted: 16 Sep 2023 15:57 Modified: 16 Nov 2023 22:32
Reporter: John Doe Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:8.1.0 OS:CentOS (7)
Assigned to: CPU Architecture:x86
Tags: Django

[16 Sep 2023 15:57] John Doe
Description:
When enabling Python warnings, the use of the django.utils.timezone.utc alias is triggering a deprecation warning from Django.

.env/lib64/python3.8/site-packages/mysql/connector/django/operations.py:79: RemovedInDjango50Warning: The django.utils.timezone.utc alias is deprecated. Please update your code to use datetime.timezone.utc instead.

How to repeat:
Use the connector and run any Python script/test/... with warnings enabled.

Suggested fix:
Import `datetime.timezone` (as `dtz` perhaps due to import conflict otherwise) and use the `timezone.utc` timezone on line 79.
[21 Sep 2023 14:43] Nuno Mariz
Using the latest Django version (4.2.5) the warning is raised.

Code:

    from django.conf import settings
    from django.utils import timezone

    settings.configure()
    print(timezone.utc)

Result:

    $ python -Wall dev_django2.py
    (snip)/test.py:5: RemovedInDjango50Warning: The django.utils.timezone.utc alias is deprecated. Please update your code to use datetime.timezone.utc instead.
      print(timezone.utc)
    UTC
[16 Nov 2023 22:32] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Python 8.3.0 release, and here's the proposed changelog entry from the documentation team:

Django would report a deprecation warning about using
django.utils.timezone.utc; updated code to instead use
datetime.timezone.utc.

Thank you for the bug report.