Hi,
What is the rigth way of catching IntegrityError, the traceback I get suggests using _mysql_exceptions.IntegrityError, which is wrong because it assumes mysql, as well as it goes against the general python guideline of not using "hidden" members of modules.
Here is my traceback:
What is the rigth way of catching IntegrityError, the traceback I get suggests using _mysql_exceptions.IntegrityError, which is wrong because it assumes mysql, as well as it goes against the general python guideline of not using "hidden" members of modules.
Here is my traceback:
>>> u = users.User(id=None, username=' [EMAIL PROTECTED]', email='[EMAIL PROTECTED]')
>>> u.save()
>>> u2 = users.User(id=None, username='[EMAIL PROTECTED] ', email='[EMAIL PROTECTED]')
>>> u2.save()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/home/l2g/amitu/DownloadServer/django_src/django/utils/functional.py", line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
File "/home/l2g/amitu/DownloadServer/django_src/django/core/meta/__init__.py", line 1026, in method_save
','.join(placeholders)), db_values)
File "/home/l2g/amitu/DownloadServer/django_src/django/core/db/base.py", line 10, in execute
result = self.cursor.execute(sql, params)
File "/home/l2g/amitu/DownloadServer/django_src/django/core/db/backends/mysql.py", line 32, in execute
return self.cursor.execute(sql, params)
File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 137, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.IntegrityError: (1062, "Duplicate entry '[EMAIL PROTECTED]' for key 2")
>>>
We should have IntegrityError and other Database error in django.common.errors or django.core.db or something, and different backends should catch database specific ones and throw these, if we are not doing it already.
Thanks,
--
Amit Upadhyay
Blog: http://www.rootshell.be/~upadhyay
+91-9867-359-701
