Session is not set in object if connection fails, which raises 'AttributeError' on __del__

Open Beginner friendly
#746 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
databases

Research direction

Start in src/databricks/sql/client.py around line 296 and inspect Connection.del along with the failed initialization path. Reproduce a connection failure with an invalid host or credentials, then verify that destroying the incomplete Connection no longer prints an AttributeError warning to stderr.

Written by the indexing model from the issue text.

Description

engineer-bot

The session attribute is set on the Connection here: https://github.com/databricks/databricks-sql-python/blob/9fe7356a18d611ae18943c2f972160657b08eea2/src/databricks/sql/client.py#L296.

If connecting fails (e.g. due to invalid host or credentials) then no session attribute will be set, but __del__ will still be called when the not-fully-initialized Connection instance is destroyed. This causes warnings to be printed to stderr.

A simple fix would be to check if session is set in open or doing the same thing in __del__ only, to keep the semantics of open intact.

Dominant language
Python
Stars
233
Forks
152
Avg merge
21h 5m
Merged PRs (30d)
10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databricks/databricks-sql-python

All issues in databricks/databricks-sql-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.