#32966 closed Bug (fixed)
Time-related _check_fix_default_value() methods can be optimized / simplified and have a bug
Reported by: | Chris Jerdonek | Owned by: | Chris Jerdonek |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I noticed that three of the _check_fix_default_value()
method definitions in django/db/models/fields/__init__.py
can be simplified. Here is one of them: https://github.com/django/django/blob/fe074c96a343530beea50fbdd0803d3e7b739e8e/django/db/models/fields/__init__.py#L1156-L1167
For example, in each of them, timezone.now()
is called even when the return value isn't needed / won't be used.
Change History (11)
comment:1 by , 3 years ago
Summary: | time-related _check_fix_default_value() methods can be simplified → time-related _check_fix_default_value() methods can be optimized / simplified |
---|
comment:2 by , 3 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 3 years ago
Summary: | time-related _check_fix_default_value() methods can be optimized / simplified → Time-related _check_fix_default_value() methods can be optimized / simplified and have a bug |
---|
comment:6 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:11 by , 3 years ago
For future reference, it turns out the bug fixed by this ticket was previously mentioned here, but never opened as a separate ticket: https://code.djangoproject.com/ticket/21905#comment:19
When I started looking at this, I noticed there is a bug on this line:
https://github.com/django/django/blob/fe074c96a343530beea50fbdd0803d3e7b739e8e/django/db/models/fields/__init__.py#L2216
It can be triggered by the following when
USE_TZ = True
:It results in:
This case is not covered in the tests here:
https://github.com/django/django/blob/fe074c96a343530beea50fbdd0803d3e7b739e8e/tests/invalid_models_tests/test_ordinary_fields.py#L743-L750