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

datetime.utcnow deprecation #8139

Open
smotornyuk opened this issue Apr 1, 2024 · 0 comments
Open

datetime.utcnow deprecation #8139

smotornyuk opened this issue Apr 1, 2024 · 0 comments

Comments

@smotornyuk
Copy link
Member

Using datetime.utcnow is not recommended because different libraries(and datetime itself) often use dates without timezone as local time. And since python v3.12 .utcnow is deprecated.

There are 47 explicit occurrences of `.utcnow` in code
ckan/lib/dictization/model_save.py:54:33: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/lib/uploader.py:159:37: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/lib/uploader.py:266:41: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/logic/action/create.py:702:29: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/logic/action/update.py:310:31: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/api_token.py:72:28: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/dashboard.py:30:44: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/dashboard.py:31:32: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/follower.py:34:25: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/user.py:34:17: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/user.py:349:36: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/model/user.py:352:32: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/cli/test_jobs.py:36:15: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/lib/test_jobs.py:147:15: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_create.py:659:16: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_get.py:3041:11: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1289:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1302:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1315:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1328:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1343:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1355:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1370:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/logic/action/test_update.py:1383:20: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_api_token.py:25:18: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_api_token.py:27:17: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_user.py:240:23: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_user.py:246:40: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_user.py:251:40: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckan/tests/model/test_user.py:256:40: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/email_notifications.py:235:9: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/email_notifications.py:259:37: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/logic/action.py:74:49: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/model/activity.py:64:26: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/tests/logic/test_action.py:27:11: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/tests/logic/test_action.py:724:18: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/tests/logic/test_action.py:745:17: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/activity/tests/logic/test_pagination.py:174:15: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:91:29: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:109:39: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:163:36: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:185:36: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:194:32: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/logic/action.py:226:32: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/tests/test_action.py:18:29: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/datapusher/tests/test_action.py:202:27: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead
ckanext/expire_api_token/plugin.py:55:21: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead

The recommended form is datetime.now(timezone.utc). But it creates a timezone-aware datetime instance. Which causes problems in several places:

Code changes are pretty straightforward. But we need to add a migration for all DB columns to switch them into timezone-aware mode. Which is potentially disruptive change for anyone who relied on dates without timezone.

There is no need to act quickly, as .utcnow only deprecated in python v3.12 and will be available for a number of versions that are not released yet. But we'll have to handle this problem at some point, so making a decision if we are going to change it by CKAN v3.0 or v2.12 is a good start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants