#32966: time-related _check_fix_default_value() methods can be optimized /
simplified
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
| Jerdonek
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Jerdonek):
* type: Cleanup/optimization => Bug
Comment:
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`:
{{{#!python
from django.db import models
import django.utils.timezone as timezone
class MyModel(models.Model):
tz = models.TimeField(default=timezone.now().timetz())
class Meta:
app_label = 'test'
field = MyModel._meta.get_field('tz')
field.check()
}}}
It results in:
{{{
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/.../django/db/models/fields/__init__.py", line 1112, in check
*self._check_fix_default_value(),
File "/.../django/db/models/fields/__init__.py", line 2220, in
_check_fix_default_value
if lower <= value <= upper:
TypeError: '<=' not supported between instances of 'datetime.datetime' and
'datetime.time'
}}}
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
--
Ticket URL: <https://code.djangoproject.com/ticket/32966#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.5a1f2f4f976901bdecd39af8a18594a4%40djangoproject.com.