-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Hello!
When a DatabricksSessionBuilder is created without required parameters being provided, calling DatabricksSession.builder.getOrCreate() returns the DatabricksSession.Builder rather than raising the exception upwards. Minimal repro:
❯ ipython
Python 3.11.11 (main, Sep 22 2025, 15:16:23) [Clang 17.0.0 (clang-1700.0.13.5)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.37.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from sqlframe.databricks import DatabricksSession
In [2]: DatabricksSession.builder.getOrCreate()
Out[2]: <sqlframe.databricks.session.DatabricksSession.Builder at 0x109bfa0d0>When running this through the debugger I get the following exception on this line:
Traceback (most recent call last):
File ".venv/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3579, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-db29ec5da713>", line 1, in <module>
conn or sql.connect(**self._conn_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/databricks/sql/__init__.py", line 90, in connect
return Connection(server_hostname, http_path, access_token, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/databricks/sql/client.py", line 219, in __init__
auth_provider = get_python_sql_connector_auth_provider(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/databricks/sql/auth/auth.py", line 116, in get_python_sql_connector_auth_provider
hostname=normalize_host_name(hostname),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/databricks/sql/auth/auth.py", line 91, in normalize_host_name
maybe_scheme = "https://" if not hostname.startswith("https://") else ""
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'
I believe that, because the Builder class implements __getattr__, and when the session property raises an AttributeError when it is evaluated, Python falls back to the __getattr__ logic rather than raising the error to the caller. To avoid confusion (it took a while to figure out why my application was getting builders where they were expecting DataFrames) it may be better to catch AttributeError here and raise a different type instead, or give DatabricksSession more robust parameter validation.
Versions:
sqlframe==3.43.8
databricks-sql-connector==3.7.4