cancel
Showing results for 
Search instead for 
Did you mean: 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results for 
Search instead for 
Did you mean: 

Streamlit app on Databricks doesn't recognise the DATABRICKS_WAREHOUSE_ID in the yaml file

AnaMocanu
New Contributor III

Hey everyone,

So I managed to create a Streamlit app on Databricks, works fine deployed in the cloud.

However, when I try to run it locally, it complains about "assert os.getenv('DATABRICKS_WAREHOUSE_ID'), "DATABRICKS_WAREHOUSE_ID must be set in app.yaml."" It looks like 

valueFrom: "sql-warehouse" is not being picked up properly in the yaml file. In the app config, it created a service principal with the "sql-warehouse" key that should pick up my serverless warehouse that I want to use.
My workaround is to specify the value of the warehouse as an environment variable in the app.py and that seems to work. 
like this:
#assert os.getenv('DATABRICKS_WAREHOUSE_ID'), "DATABRICKS_WAREHOUSE_ID must be set in app.yaml."
os.environ['DATABRICKS_WAREHOUSE_ID'] = my_value
 
Any thoughts on how to enforce the yaml file to pick up the right values?
 
Many thanks!
Ana
2 REPLIES 2

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @AnaMocanu,

How are you setting up: DATABRICKS_WAREHOUSE_ID?

When running the app locally, the environment variables set in the app.yaml file might not be picked up automatically. You can manually set the environment variable in your local environment before running the app. For example, in a Unix-based system, you can use

export DATABRICKS_WAREHOUSE_ID=<your_warehouse_id>
streamlit run app.py

Additionally, you might want to implement some prints to validate if information is correct:

import os
print("DATABRICKS_WAREHOUSE_ID:", os.getenv('DATABRICKS_WAREHOUSE_ID'))

Hi @Alberto_Umana 

Thanks for your reply!
DATABRICKS_WAREHOUSE_ID is set up in yaml file like this:

env:
- name: "DATABRICKS_WAREHOUSE_ID"
valueFrom: "sql-warehouse"
 
When the app is running on Databricks, I can see a Service principal in app resources that has the value set up.
AnaMocanu_0-1734389590650.png

Your suggestion is how I hack it at the moment, I'm setting up the id manually, but I don't want to do it like that, cause I'm using a serverless warehouse and that value could change?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group