r-dbi / odbc

Connect to ODBC databases (using the DBI interface)
https://odbc.r-dbi.org/
Other
387 stars 107 forks source link

`odbc::databricks()` does not detect Workbench-managed credentials when rendering Quarto/RMarkdown docs #803

Closed atheriel closed 3 months ago

atheriel commented 3 months ago

This is a standalone issue to track the problem first reported for Snowflake by @chendaniely.

Given the following Quarto doc that picks up on Workbench-managed credentials just fine in the console:

---
title: "Databricks Demo"
format: html
---

```{r}
library(odbc)

conn <- DBI::dbConnect(
  odbc::databricks(),
  httpPath = "/sql/1.0/warehouses/300bd24ba12adf8e"
)

Clicking `Render` in the RStudio Pro UI gives the following output:

processing file: databricks-demo.qmd |................................... | 67% [unnamed-chunk-1] Quitting from lines at lines 7-13 [unnamed-chunk-1] (databricks-demo.qmd) Error in DBI::dbConnect(): ! ✖ Failed to detect ambient Databricks credentials. ℹ Supply uid and pwd to authenticate manually. Backtrace:

  1. DBI::dbConnect(odbc::databricks(), httpPath = "/sql/1.0/warehouses/300bd24ba12adf8e")
  2. DBI::dbConnect(odbc::databricks(), httpPath = "/sql/1.0/warehouses/300bd24ba12adf8e")
  3. odbc (local) .local(drv, ...)
  4. odbc:::databricks_args(...) at odbc/R/driver-databricks.R:78:5

Execution halted



This is because we use `.rs.api.getDatabricksToken()`, which isn't available in child processes. We should move to reading the file directly, like we now do for Snowflake.