Skip to content

Fix USE_TZ RemovedInDjango50Warning #1573

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

Merged
merged 1 commit into from
Jan 12, 2022
Merged

Conversation

adamchainz
Copy link
Contributor

Fix this warning, which appears in both the docs build and Django 4.0 tests:

/.../python3.8/site-packages/django/conf/__init__.py:199: RemovedInDjango50Warning: The default value of USE_TZ will change from False to True in Django 5.0. Set USE_TZ to False in your project settings if you want to keep the current default behavior.

@adamchainz
Copy link
Contributor Author

Okay looks like the test suite needs adjustment...

Comment on lines -124 to +130
list(User.objects.filter(date_joined=datetime.datetime(2017, 12, 22, 16, 7, 1)))
list(
User.objects.filter(
date_joined=datetime.datetime(
2017, 12, 22, 16, 7, 1, tzinfo=datetime.timezone.utc
)
)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change from naive datetime, which django will interpret with the default timezone, to aware


DATA = {"value": "foo", "date": datetime(2020, 1, 1)}
SIGNED_DATA = f'{{"date": "2020-01-01 00:00:00", "value": "foo"}}:{SIGNATURE}'
DATA = {"value": "foo", "date": datetime(2020, 1, 1, tzinfo=timezone.utc)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this changes the naive datetime to aware, so that it isn't interpreted with the default timezone when converting to str

Comment on lines +145 to +149
if connection.vendor == "postgresql":
# PostgreSQL always includes timezone
expected_datetime = '["2017-12-22 16:07:01+00:00"]'
else:
expected_datetime = '["2017-12-22 16:07:01"]'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new formatting difference being triggered on PostgreSQL

Fix this warning, which appears in both the docs build and Django 4.0 tests:

```
/.../python3.8/site-packages/django/conf/__init__.py:199: RemovedInDjango50Warning: The default value of USE_TZ will change from False to True in Django 5.0. Set USE_TZ to False in your project settings if you want to keep the current default behavior.
```
@matthiask matthiask merged commit 95a6874 into django-commons:main Jan 12, 2022
@matthiask
Copy link
Member

Very nice, thanks!

@adamchainz adamchainz deleted the use_tz branch January 12, 2022 13:29
gone pushed a commit to gone/django-debug-toolbar that referenced this pull request Jan 16, 2022
Fix this warning, which appears in both the docs build and Django 4.0 tests:

```
/.../python3.8/site-packages/django/conf/__init__.py:199: RemovedInDjango50Warning: The default value of USE_TZ will change from False to True in Django 5.0. Set USE_TZ to False in your project settings if you want to keep the current default behavior.
```
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

Successfully merging this pull request may close these issues.

2 participants