-
Notifications
You must be signed in to change notification settings - Fork 442
mysqlclient raises OperationalError instead of IntegrityError for all Constraint Violations #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 If one wants to do retries for OperationalErrors for resilience, they must look for application/integrity errors inside OperationalError manually (like forementioned constraint violations which are not retryable) |
I see IntegrityError for this query. And its result: |
Thanks @methane |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
mysqlclient is raising OperationalError instead of IntegrityError for all constraint violations, such as not null, unique, foreign key, and check.
This is a bug because it violates the Python DB API PEP 0249. In addition, all other python drivers like mysql-connector-python, PyMySQL, cx_Oracle, psycopg2, and etc. will correctly raise IntegrityError in these cases. It seems like only mysqlclient raises OperationalError.
The Python DB API pep is clear that an IntegrityError should be raised in this case, not OperationalError. Please see the PEP here:
https://peps.python.org/pep-0249/#integrityerror
The PEP states that OperationalError is used for totally different errors not under the control of the programmer, such as running out of memory. Please read the description for OperationalError here: https://peps.python.org/pep-0249/#operationalerror
To Reproduce
Environment
MySQL Server
MySQL Client
OS (e.g. Windows 10, Ubuntu 20.04): Windows 10
Python (e.g. Homebrew Python 3.7.5): Python 3.9
Connector/C (e.g. Homebrew mysql-client 8.0.18): pip install mysqlclient==2.1.0
The text was updated successfully, but these errors were encountered: