AttributeError during pd.read_sql_table

Open
#278 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Reproduce the pd.read_sql_table example with SQLAlchemy 1.4.22 and databricks-sql-connector 2.9.3, then inspect src/databricks/sqlalchemy/base.py around line 360 and src/databricks/sqlalchemy/dialect/init.py around lines 247 and 299. Done means table reflection completes without the reported AttributeError.

Written by the indexing model from the issue text.

Description

bug

SQLAlchemy version: 1.4.22
databricks-sql-connector version: 2.9.3

The following code throws the error below:

from sqlalchemy import create_engine
[...]
conn = create_engine(
    f"databricks://token:{token}@{host}?http_path={path}"
    "&catalog={catalog}&schema={schema}"
)
test = pd.read_sql_table(table, con=conn)

File "[REDACTED]\sqlalchemy\engine\reflection.py", line 266, in get_table_names
return self.dialect.get_table_names(
File "[REDACTED]\databricks\sqlalchemy\dialect_init_.py", line 247, in get_table_names
with self.get_connection_cursor(connection) as cur:
File "[REDACTED]\databricks\sqlalchemy\dialect_init_.py", line 299, in get_connection_cursor
return connection._dbapi_connection.dbapi_connection.cursor()
File "[REDACTED]\sqlalchemy\pool\base.py", line 985, in getattr
return getattr(self.connection, key)
AttributeError: 'Connection' object has no attribute 'dbapi_connection'

I believe the line linked below should read connection._dbapi_connection.cursor() (attr exists) instead of connection._dbapi_connection.dbapi_connection.cursor() (attr doesnt exist)

https://github.com/databricks/databricks-sql-python/blame/0e7ce57ae4fecc364c4de55d6adace33c39aff5f/src/databricks/sqlalchemy/base.py#L360C13-L360C74

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.