| Bug #72732 | time variable (TimeField) with 00:00:00 value converts to NULL in the SQL | ||
|---|---|---|---|
| Submitted: | 23 May 2014 22:06 | Modified: | 26 Jun 2014 17:21 |
| Reporter: | Sergey Stepanov | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / Python | Severity: | S2 (Serious) |
| Version: | mysql-connector-python==1.1.6 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | django timefield | ||
[23 May 2014 22:13]
Sergey Stepanov
it's actual only for python version less than 3.5 in 3.5 they are fixing boolean midnight behavior http://hg.python.org/cpython/rev/89aa669dcc61/
[11 Jun 2014 11:14]
Peeyush Gupta
Thank you for the report. Verified as described using code analysis.
[26 Jun 2014 17:21]
Paul DuBois
Noted in 1.2.3 changelog. Django TimeField values of 00:00:00 were incorrectly converted to NULL because Python considered that value equal to False.
[11 Jul 2014 14:25]
Paul DuBois
Posted by developer: Noted in 2.0.0 changelog.

Description: Using Django and mysql-connector-python==1.1.6, when I try to insert (update) a TimeField (time column in MYSQL), converter transforms it into NULL, instead of 1900-01-01 00:00:00. And that ruins query if field is not set to null=True (not nullable in DB) If the field is set to null=True, then I have to explicitly check it for NoneType at the framework, because NULL doesn't convert to 00:00:00 automatically. How to repeat: Get a TimeField in any model of django app and try to insert new instance with 00:00:00 value for that field (in admin panel e.g.) Suggested fix: change code at line 400 of mysql/connector/django/base.py: "def value_to_db_time(self, value): if not value: return None" 00:00:00 time variable considered as False by Python. There must be other type of check, but don't know which one is better in that case