Skip to content

Commit

Permalink
Don't try to import runtime_auth when not in runtime (#327)
Browse files Browse the repository at this point in the history
## Changes
Runtime auth is attempted when we do not have any config variables set
(either directly in the sdk config, in .databrickcfg or as env vars).
This further attempts importing runtime_auth functions from the
dbruntime package. These are not available outside dbr.

This PR moves "is in dbr runtime" check before the import, so that the
import is not attempted outside dbr and users don't get cryptic errors.
## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [ ] `make test` run locally
- [ ] `make fmt` applied
- [ ] relevant integration tests applied

---------

Signed-off-by: Kartik Gupta <88345179+kartikgupta-db@users.noreply.github.com>
Co-authored-by: Serge Smertin <259697+nfx@users.noreply.github.com>
  • Loading branch information
kartikgupta-db and nfx authored Sep 5, 2023
1 parent af9b8fc commit aaabc34
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions databricks/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ def inner() -> Dict[str, str]:

@credentials_provider('runtime', [])
def runtime_native_auth(cfg: 'Config') -> Optional[HeaderFactory]:
if 'DATABRICKS_RUNTIME_VERSION' not in os.environ:
return None

# This import MUST be after the "DATABRICKS_RUNTIME_VERSION" check
# above, so that we are not throwing import errors when not in
# runtime and no config variables are set.
from databricks.sdk.runtime import (init_runtime_legacy_auth,
init_runtime_native_auth,
init_runtime_repl_auth)
if 'DATABRICKS_RUNTIME_VERSION' not in os.environ:
return None
for init in [init_runtime_native_auth, init_runtime_repl_auth, init_runtime_legacy_auth]:
if init is None:
continue
Expand Down

0 comments on commit aaabc34

Please sign in to comment.