Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the deprecated pytz package #33980

Open
UsamaSadiq opened this issue Dec 28, 2023 · 3 comments
Open

Remove the deprecated pytz package #33980

UsamaSadiq opened this issue Dec 28, 2023 · 3 comments
Assignees

Comments

@UsamaSadiq
Copy link
Member

UsamaSadiq commented Dec 28, 2023

Description

  • pytz got deprecated in Django 4.0 && has been completely removed in Django 5.0.
  • Django 4.2 had provided USE_DEPRECATED_PYTZ flag for pytz support which has now been completely removed in Django 5.0 as well.
  • Django now uses zoneinfo by default and datetime module use this under the hood now instead of pytz

Difference between datetime.timezone and zoneinfo

datetime.timezone and the zoneinfo package are both related to handling time zones in Python, but they serve slightly different purposes and have different use cases.

datetime.timezone

  • This is part of the standard library in Python.
  • It provides a simple way to represent a fixed offset from UTC (Coordinated Universal Time).
  • It doesn't have information about daylight saving time (DST) or historical changes in time zones.
  • It's suitable for scenarios where you only need to work with a constant offset, and historical changes in time zones are not important.

zoneinfo

  • The zoneinfo package is introduced in Python 3.9 as part of PEP 615.
  • It provides a more comprehensive and accurate way to handle time zones by including historical changes, daylight saving time transitions, and more.
  • It uses the IANA Time Zone Database, which is regularly updated to reflect changes in time zones around the world.
  • This package is suitable for applications that require precise handling of time zones, especially when dealing with historical dates.

pytz usages to replace

  • import pytz → 268 files in openedx/edx-platform.
  • pytz.UTC → 97 files in openedx/edx-platform.

Potential Solution

Approach 01

  • Replace pytz.UTC with backports.zoneinfo.UTC
  • Migrate to Python>3.9
  • Replace backports.zoneinfo with zoneinfo

Approach 02

  • Upgrade from Python 3.8 to Python 3.9
  • Replace pytz.UTC with zoneinfo.UTC
@UsamaSadiq UsamaSadiq moved this to In Progress in Arbi-BOM Dec 28, 2023
@UsamaSadiq UsamaSadiq self-assigned this Dec 28, 2023
@iamsobanjaved
Copy link
Contributor

We will be doing the Python 3.11 upgrade well before the Django 5.2 upgrade, so I think we can opt for second approach, do this after the Python 3.11 upgrade.

@jmbowman jmbowman removed this from Arch-BOM Jan 2, 2024
@UsamaSadiq UsamaSadiq moved this from In Progress to Blocked in Arbi-BOM Jan 15, 2024
@iamsobanjaved iamsobanjaved moved this from Blocked to Todo in Arbi-BOM Jul 11, 2024
@iamsobanjaved
Copy link
Contributor

As we are on Python 3.11, this is unblocked now.

@mfarhan943 mfarhan943 self-assigned this Sep 19, 2024
@mfarhan943 mfarhan943 moved this from Todo to In Progress in Arbi-BOM Sep 19, 2024
@mfarhan943
Copy link
Contributor

https://github.com/search?q=repo%3Aopenedx%2Fedx-platform+country_timezones+language%3APython&type=code
There isn't a built-in function for country_timezones in the zoneinfo module. To create a custom one, we would need to hardcode a list of countries and their associated timezones.

@UsamaSadiq UsamaSadiq moved this from Author Team Review to Blocked in Arbi-BOM Oct 21, 2024
@mfarhan943 mfarhan943 moved this from Blocked to Author Team Review in Arbi-BOM Nov 15, 2024
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

No branches or pull requests

4 participants