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

use django timezone util to avoid runtime warnings #34

Merged
merged 2 commits into from
Jan 24, 2024
Merged

Conversation

snopoke
Copy link
Contributor

@snopoke snopoke commented Jan 24, 2024

Depending on the Django settings the DateTimeField expects either a naive or non-naive datetime object. A runtime warning is emitted if the field receives a value it is not expecting.

Using django.utils.timezone.now solves this since it returns the datetime with the correct TZ value.

Warning message for reference:

 .../django/db/models/fields/__init__.py:1595: RuntimeWarning: DateTimeField AuditEvent.event_date received a naive datetime (2024-01-24 09:28:14.565753) while time zone support is active.

Depending on the Django settings the DateTimeField expects
either a naive or non-naive datetime object. A runtime warning
is emitted if the field receives a value it is not expecting.

Using `django.utils.timezone.now` solves this since it returns
the datetime with the correct TZ value.
@snopoke snopoke merged commit 6c37936 into main Jan 24, 2024
10 checks passed
@snopoke snopoke deleted the sk/event-date branch January 24, 2024 14:00
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