-
Notifications
You must be signed in to change notification settings - Fork 27
FEAT: Adding Conn.Error #164
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances DB-API 2.0 compliance by adding exception handling attributes to the Connection class and improving error handling in the Cursor class. The changes enable users to catch exceptions using connection-based attributes like connection.Error and connection.ProgrammingError as required by the DB-API 2.0 specification.
- Added all standard DB-API 2.0 exception classes as attributes on the Connection class
- Updated cursor error handling to raise
InterfaceErrorinstead of genericExceptionfor closed cursor operations - Added comprehensive tests covering exception attributes, inheritance, instantiation, and real-world error scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mssql_python/connection.py | Imports all DB-API 2.0 exception classes and adds them as class attributes to enable connection-based exception handling |
| mssql_python/cursor.py | Updates error handling in cursor close operations to raise InterfaceError instead of generic Exception |
| tests/test_003_connection.py | Adds extensive test coverage for exception attributes, inheritance hierarchy, instantiation, and error handling scenarios |
Comments suppressed due to low confidence (2)
tests/test_003_connection.py:290
- [nitpick] The variable name
warningconflicts with Python's built-inwarningmodule. Consider renaming it towarning_instanceortest_warningto avoid potential confusion.
warning = db_connection.Warning("Test warning", "DDBC warning")
tests/test_003_connection.py:294
- [nitpick] The variable name
erroris too generic and could be confusing in an error handling context. Consider renaming it toerror_instanceortest_errorfor clarity.
error = db_connection.Error("Test error", "DDBC error")
… jahnvi/conn_exceptions
sumitmsft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left few comments.. Please resolve them
Work Item / Issue Reference
Summary
This pull request enhances DB-API 2.0 compliance for exception handling in the
mssql_pythonpackage. The main changes are the addition of all standard DB-API 2.0 exception classes as attributes on theConnectionclass, refactoring error handling in theCursorclass to use these exceptions, and introducing comprehensive tests to verify correct behavior, inheritance, and consistency of these exception attributes.DB-API 2.0 Exception Support
Added all DB-API 2.0 exception classes (
Warning,Error,InterfaceError,DatabaseError,DataError,OperationalError,IntegrityError,InternalError,ProgrammingError,NotSupportedError) as attributes on theConnectionclass, making it possible to catch exceptions usingconnection.Error,connection.ProgrammingError, etc. (mssql_python/connection.py)Error Handling Improvements
Updated the
Cursorclass to raiseInterfaceError(instead of genericException) when operations are attempted on a closed cursor, ensuring proper use of DB-API exceptions. (mssql_python/cursor.py)Testing Enhancements
Connectioninstances and the class itself.tests/test_003_connection.py)