-
Notifications
You must be signed in to change notification settings - Fork 21
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
InterfaceError
instead of genericException
for 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
warning
conflicts with Python's built-inwarning
module. Consider renaming it towarning_instance
ortest_warning
to avoid potential confusion.
warning = db_connection.Warning("Test warning", "DDBC warning")
tests/test_003_connection.py:294
- [nitpick] The variable name
error
is too generic and could be confusing in an error handling context. Consider renaming it toerror_instance
ortest_error
for clarity.
error = db_connection.Error("Test error", "DDBC error")
… jahnvi/conn_exceptions
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_python
package. The main changes are the addition of all standard DB-API 2.0 exception classes as attributes on theConnection
class, refactoring error handling in theCursor
class 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 theConnection
class, making it possible to catch exceptions usingconnection.Error
,connection.ProgrammingError
, etc. (mssql_python/connection.py
)Error Handling Improvements
Updated the
Cursor
class 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
Connection
instances and the class itself.tests/test_003_connection.py
)