Conversation
Contributor
There was a problem hiding this comment.
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")
bewithgaurav
previously approved these changes
Aug 5, 2025
… jahnvi/conn_exceptions
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
requested changes
Aug 22, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Left few comments.. Please resolve them
sumitmsft
approved these changes
Aug 26, 2025
gargsaumya
approved these changes
Aug 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)