Opened 2 years ago

Closed 2 years ago

#33602 closed Bug (invalid)

date_hierarchy in admin reports an error with mysql-connector-python 8.0.28.

Reported by: Eric Pan Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

\site-packages\django\db\backends\mysql\operations.py line 58

def date_trunc_sql(self, lookup_type, field_name, tzname=None):
        field_name = self._convert_field_to_tz(field_name, tzname)
        fields = {
            'year': '%%Y-01-01',
            'month': '%%Y-%%m-01',
        }  # Use double percents to escape.

the problem is here.

   'year': '%%Y-01-01',
            'month': '%%Y-%%m-01',

this will generate the SQL.

SELECT DISTINCT CAST(DATE_FORMAT([table name], '%%Y-01-01') AS DATE) AS `datefield

the format ''%%Y-01-01'' is not right for mysql.

Change History (4)

comment:1 by Tim Graham, 2 years ago

Component: contrib.adminDatabase layer (models, ORM)
Description: modified (diff)
Resolution: needsinfo
Status: newclosed
Type: UncategorizedBug

This might be a bug in mysql-connector-python and/or mysql.connector.django which aren't part of Django itself.

What does "the format ... is not right" mean? What's the error?

comment:2 by Eric Pan, 2 years ago

the error message is:

django.db.utils.DatabaseError: (1292, "1292: Incorrect datetime value: '%Y-01-01'", None)

and the sql text sent to mysql db is 'SELECT DISTINCT CAST(DATE_FORMAT([table name], '%%Y-01-01') AS DATE) AS `datefield

it seems the double %% not be escaped to single % in the final sql text sent to mysql.

I don not know it's the issue of mysql-connector-python or Django it self.

because the sql was generated in django module.
\site-packages\django\db\backends\mysql\operations.py line 58

comment:3 by Eric Pan, 2 years ago

Resolution: needsinfo
Status: closednew

comment:4 by Mariusz Felisiak, 2 years ago

Resolution: invalid
Status: newclosed
Summary: when use date_hierarchy in admin, it report a error. django 3.2.12, mysql-connector-python8.0.28, mysql server 8.0.28date_hierarchy in admin reports an error with mysql-connector-python 8.0.28.

Everything works fine with the recommended mysqlclient driver. mysql-connector-python includes its own adapter 'mysql.connector.django' which may not support the most recent releases of Django (as documented). You can try to report this issue in MySQL bugtracker.

Note: See TracTickets for help on using tickets.
Back to Top