microsoft / mssql-django

The Microsoft Django backend for SQL Server provides a connectivity layer for Django on SQL Server or Azure SQL DB.
Other
351 stars 115 forks source link

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

Open rgasper opened 1 year ago

rgasper commented 1 year ago

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: https://github.com/microsoft/mssql-django/blob/a429dd17f2412d67c9442ecfe3abe21836cffdf0/mssql/base.py#L504

rgasper commented 1 year ago

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 1 year ago

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