Bug #106867 Django date_hierarchy in admin reports an error with mysql-connector-python 8.0.
Submitted: 29 Mar 2022 23:48 Modified: 4 May 2022 4:42
Reporter: 伟峰 潘 Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version: OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any

[29 Mar 2022 23:48] 伟峰 潘
Description:
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

Django Teams answered me:

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.

How to repeat:
set date_hierarchy in django model admin class
and you can see the error

Suggested fix:
Django Teams answered me:

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.
[4 Apr 2022 4:42] MySQL Verification Team
Hello,

Thank you for the bug report.
Could you please let us know in what operation you are getting this error? It would be helpful if you can include the models as well. Thanks.

Regards,
Ashwini Patil
[5 May 2022 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".