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

Forbid datetime.now and timezone.now in default #12

Open
sobolevn opened this issue Oct 30, 2020 · 1 comment
Open

Forbid datetime.now and timezone.now in default #12

sobolevn opened this issue Oct 30, 2020 · 1 comment

Comments

@sobolevn
Copy link
Contributor

sobolevn commented Oct 30, 2020

People use timezone.now (sometimes even timezone.now()) as a default value.
But, there are auto_now_add=True and auto_now=True for DateTimeField.

Sub-checks:

  • timezone.now() is evaluated once, use timezone.now
  • Don't use datetime.now, it does not have a proper timezone support
@kalekseev
Copy link
Owner

timezone.now() is evaluated once, use timezone.now

this case is checked by fields.W161 https://docs.djangoproject.com/en/3.1/ref/checks/#model-fields

But, there are auto_now_add=True and auto_now=True for DateTimeField

auto keywords and default=timezone.now yield different results, so I'm not sure that we should have opinion about that.

Don't use datetime.now, it does not have a proper timezone support

that one looks like a good candidate for check

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