-
Notifications
You must be signed in to change notification settings - Fork 14
[PECOBLR-1655] Implemented the functionality of pool_pre_ping #53
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
Open
msrathore-db
wants to merge
7
commits into
main
Choose a base branch
from
PECOBLR-1655
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a6a3564
Implemented the functionality of poll_pre_ping which executes a query…
msrathore-db d2a3339
Added functionality for is_disconnect()
msrathore-db 77138f3
Implemented is_disconnect and removed the do_ping implementation keep…
msrathore-db 1e47cb2
Pin poetry version to 2.2.1 to fix CI failures
msrathore-db c3ae658
Fix is_disconnect to handle closed connection errors
msrathore-db 6936842
Run black formatter on base.py
msrathore-db 0145f62
Improve is_disconnect error handling precision
msrathore-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| """Tests for DatabricksDialect.is_disconnect() method.""" | ||
| import pytest | ||
| from databricks.sqlalchemy import DatabricksDialect | ||
| from databricks.sql.exc import ( | ||
| Error, | ||
| InterfaceError, | ||
| DatabaseError, | ||
| OperationalError, | ||
| RequestError, | ||
| SessionAlreadyClosedError, | ||
| CursorAlreadyClosedError, | ||
| MaxRetryDurationError, | ||
| NonRecoverableNetworkError, | ||
| UnsafeToRetryError, | ||
| ) | ||
|
|
||
|
|
||
| class TestIsDisconnect: | ||
| @pytest.fixture | ||
| def dialect(self): | ||
| return DatabricksDialect() | ||
|
|
||
| # --- InterfaceError: closed connection/cursor (client.py) --- | ||
|
|
||
| def test_interface_error_closed_connection(self, dialect): | ||
| """All InterfaceError messages with 'closed' are disconnects.""" | ||
| test_cases = [ | ||
| InterfaceError("Cannot create cursor from closed connection"), | ||
| InterfaceError("Cannot get autocommit on closed connection"), | ||
| InterfaceError("Cannot set autocommit on closed connection"), | ||
| InterfaceError("Cannot commit on closed connection"), | ||
| InterfaceError("Cannot rollback on closed connection"), | ||
| InterfaceError("Cannot get transaction isolation on closed connection"), | ||
| InterfaceError("Cannot set transaction isolation on closed connection"), | ||
| InterfaceError("Attempting operation on closed cursor"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| def test_interface_error_without_closed_not_disconnect(self, dialect): | ||
| """InterfaceError without 'closed' is not a disconnect.""" | ||
| error = InterfaceError("Some other interface error") | ||
| assert dialect.is_disconnect(error, None, None) is False | ||
|
|
||
| # --- RequestError: transport/network-level errors --- | ||
|
|
||
| def test_request_error_is_disconnect(self, dialect): | ||
| """All RequestError instances are disconnects.""" | ||
| test_cases = [ | ||
| RequestError("HTTP client is closing or has been closed"), | ||
| RequestError("Connection pool not initialized"), | ||
| RequestError("HTTP request failed: max retries exceeded"), | ||
| RequestError("HTTP request error: connection reset"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| def test_request_error_subclasses_are_disconnect(self, dialect): | ||
| """RequestError subclasses are all disconnects.""" | ||
| test_cases = [ | ||
| SessionAlreadyClosedError("Session already closed"), | ||
| CursorAlreadyClosedError("Cursor already closed"), | ||
| MaxRetryDurationError("Retry duration exceeded"), | ||
| NonRecoverableNetworkError("HTTP 501"), | ||
| UnsafeToRetryError("Unexpected HTTP error"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| # --- DatabaseError: server-side session/operation errors --- | ||
|
|
||
| def test_database_error_with_invalid_handle(self, dialect): | ||
| """DatabaseError with 'invalid handle' is a disconnect.""" | ||
| test_cases = [ | ||
| DatabaseError("Invalid SessionHandle"), | ||
| DatabaseError("[Errno INVALID_HANDLE] Session does not exist"), | ||
| DatabaseError("INVALID HANDLE"), | ||
| DatabaseError("invalid handle"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| def test_database_error_unexpectedly_closed_server_side(self, dialect): | ||
| """DatabaseError for operations closed server-side is a disconnect.""" | ||
| test_cases = [ | ||
| DatabaseError("Command abc123 unexpectedly closed server side"), | ||
| DatabaseError("Command None unexpectedly closed server side"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| def test_database_error_without_disconnect_indicators(self, dialect): | ||
| """DatabaseError without disconnect indicators is not a disconnect.""" | ||
| test_cases = [ | ||
| DatabaseError("Syntax error in SQL"), | ||
| DatabaseError("Table not found"), | ||
| DatabaseError("Permission denied"), | ||
| DatabaseError("Catalog name is required for get_schemas"), | ||
| DatabaseError("Catalog name is required for get_columns"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is False | ||
|
|
||
| # --- OperationalError (non-RequestError) --- | ||
|
|
||
| def test_operational_error_not_disconnect(self, dialect): | ||
| """OperationalError without disconnect indicators is not a disconnect.""" | ||
| test_cases = [ | ||
| OperationalError("Timeout waiting for query"), | ||
| OperationalError("Empty TColumn instance"), | ||
| OperationalError("Unsupported TRowSet instance"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is False | ||
|
|
||
| # --- Base Error class: older connector versions (client.py:385) --- | ||
|
|
||
| def test_base_error_closed_connection_is_disconnect(self, dialect): | ||
| """Base Error with 'closed connection/cursor' is a disconnect. | ||
|
|
||
| Older released versions of databricks-sql-connector raise Error | ||
| (not InterfaceError) for closed connection messages. | ||
| """ | ||
| test_cases = [ | ||
| Error("Cannot create cursor from closed connection"), | ||
| Error("Cannot get autocommit on closed connection"), | ||
| Error("Attempting operation on closed cursor"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is True | ||
|
|
||
| def test_base_error_without_closed_not_disconnect(self, dialect): | ||
| """Base Error without 'closed connection/cursor' is not a disconnect.""" | ||
| test_cases = [ | ||
| Error("Some other error"), | ||
| Error("Connection timeout"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is False | ||
|
|
||
| # --- Other exceptions --- | ||
|
|
||
| def test_other_errors_not_disconnect(self, dialect): | ||
| """Non-connector exception types are not disconnects.""" | ||
| test_cases = [ | ||
| Exception("Some random error"), | ||
| ValueError("Bad value"), | ||
| RuntimeError("Runtime failure"), | ||
| ] | ||
| for error in test_cases: | ||
| assert dialect.is_disconnect(error, None, None) is False |
Oops, something went wrong.
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.
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.
InterfaceError can also be raised for programming errors like invalid params. Will this be an expected behavior then?
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.
That's not the case with the current connector. All the interface errors are raised when connection is closed.