Skip to content
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

Bad exception raised for null inserts #3

Closed
claudep opened this issue Sep 8, 2014 · 2 comments · Fixed by #6
Closed

Bad exception raised for null inserts #3

claudep opened this issue Sep 8, 2014 · 2 comments · Fixed by #6

Comments

@claudep
Copy link

claudep commented Sep 8, 2014

The legacy MySQLdb1 raises an IntegrityError when doing a null insert in a not-nullable column. Apparently, this fork is raising OperationalError. The old behavior should be restored if possible.

@methane
Copy link
Member

methane commented Sep 9, 2014

MySQLdb1 also raises OperationalError.
django.db.backend.mysql convert OperationalError to IntegrityError.
https://github.com/django/django/blob/master/django/db/backends/mysql/base.py#L129-134

@methane
Copy link
Member

methane commented Sep 9, 2014

OK. mysqlclient fails to reraise exception.

In [28]: try:
   ....:     cur.execute("INSERT INTO model_fields_booleanmodel (bfield, string) values (NULL, 'xyz')")
   ....: except Exception as e:
   ....:     exc = e
In [29]: e
Out[29]:
_mysql_exceptions.OperationalError(_mysql_exceptions.OperationalError(1048,
                                                                      "Column 'bfield' cannot be null"))

In [30]: e.args
Out[30]: (_mysql_exceptions.OperationalError(1048, "Column 'bfield' cannot be null"),)

In [31]: e.args[0]
Out[31]: _mysql_exceptions.OperationalError(1048, "Column 'bfield' cannot be null")

In [32]: e.args[0][0]
Out[32]: 1048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants