microsoft/mssql-django

[FEATURE REQUEST] Database errors should be translated from generic errors to PEP249-compliant errors

rgasper opened this issue · 2 comments

Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it
With the exception of back-off errors that are handled, database errors get raised as "raw" Error objects, making catching them properly more challenging.

Describe the preferred solution
Database errors should be caught, their codes parsed, and re-raised as one of the PEP-249 error types.

Reference Documentations/Specifications
https://docs.djangoproject.com/en/4.2/ref/exceptions/#database-exceptions
https://peps.python.org/pep-0249/

Looks like the correct spot to fix this would go quite naturally in this function:

def _on_error(self, e):

The specific error I was experiencing that wasn't getting handled was

IMC06 | The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.

Which was raised as a Database.Error with that detail message

mShan0 commented

Thanks for bringing this up. This is definitely something we'll look into doing.