What you will be able to do
- Install a test app in development mode from staged files or a version and upgrade it while you iterate
- Use debug mode to find objects the setup script never granted to an application role, and fix the grant in SQL
- Choose between the AS_APPLICATION and AS_SETUP_SCRIPT execution contexts in session debug mode
- Gate Streamlit features with IS_APPLICATION_ROLE_IN_SESSION and place environment.yml correctly
1.Installing a test app in development mode
Before an app reaches any consumer, the provider installs it in their own account and runs it there. The setup script runs in this case too, when a provider creates or upgrades an app to test the application package. An app created from files on a stage or from a version, in the same account as its application package, is in development mode. Development mode is what makes the other testing tools available. Debug mode, session debug mode and turning off redaction all require it.
In development mode you see the app as a consumer would. DESC APPLICATION lists only the schemas the app's application roles allow. Each iteration is an upgrade, not a reinstall. You change the files on the stage and upgrade the test app from them, or move it to another version with UPGRADE USING VERSION. App code can call IS_DEV_MODE to check whether it was installed in development mode.
ALTER APPLICATION hello_snowflake_app
UPGRADE USING VERSION v1_1;Test the privilege flow before consumers hit it. Under manifest_version: 2, privileges such as CREATE WAREHOUSE, CREATE DATABASE or EXECUTE TASK are granted automatically on install and upgrade. Others, including MANAGE WAREHOUSES, READ SESSION and EXECUTE ALERT, must be granted manually. In a test install you grant those yourself with SQL and confirm the app behaves correctly both before and after the grant. How consumers grant privileges is covered in Consumer privilege-granting workflow. An application role created by the setup script is automatically granted to the role that owns the app. As the owner you therefore already hold every app role, and you only see the narrower consumer view by granting a role to another role and testing with that role.
Checkpoint 1 of 4· Check yourself
You install a test app from your stage in development mode. Its manifest uses manifest_version: 2 and requests four privileges. Which one must you grant yourself with SQL, so you can test the app both before and after the grant?
Under manifest_version: 2, CREATE WAREHOUSE, EXECUTE TASK and CREATE DATABASE are granted automatically on install and upgrade. MANAGE WAREHOUSES is not, so in a test install you grant it manually and check how the app behaves before and after.
“For example, the following privileges aren’t automatically granted to the app: MANAGE WAREHOUSES”Source: docs.snowflake.com
2.Debug mode: seeing what the setup script hid
Debug mode lets you see and change every object in the app, including objects the setup script never granted to an application role. It is a property of the app, not of your session. It stays on in every session until you turn it off. Setting it requires OWNERSHIP on the app and DEVELOP on the application package. On an app that isn't in development mode, the command fails with error 093039.
ALTER APPLICATION hello_snowflake_app SET DEBUG_MODE = TRUE;
ALTER APPLICATION hello_snowflake_app SET DEBUG_MODE = FALSE;Debug mode is most useful for comparing the two views. An object you can see with debug mode on but not with it off has no grant to any application role, so consumers can't see or use it either. The setup script below creates core.config but grants nothing on it. With debug mode off, SHOW TABLES IN APPLICATION returns no rows and a SELECT fails with 002003 ... does not exist or not authorized. With debug mode on, both work.
CREATE APPLICATION ROLE IF NOT EXISTS app_public;
CREATE OR ALTER VERSIONED SCHEMA core;
GRANT USAGE ON SCHEMA core TO APPLICATION ROLE app_public;
CREATE TABLE IF NOT EXISTS core.config (k VARCHAR, v VARCHAR);You fix it in SQL, in the setup script, not by changing settings on the test install. Add the grant to the application role and upgrade from the staged files. After that, any role granted app_public can query the table. What application roles are and how they form a hierarchy is covered in Application roles.
GRANT SELECT ON TABLE core.config TO APPLICATION ROLE app_public;
ALTER APPLICATION hello_snowflake_app
UPGRADE USING '@hello_snowflake_code.core.hello_snowflake_stage';In debug mode you keep acting as yourself, so anything you create is owned by your current role. To act as the app itself you need the other mode.
Checkpoint 2 of 4· Check yourself
You installed a test app in your own account from a release directive, the way a consumer would, and now run ALTER APPLICATION ... SET DEBUG_MODE = TRUE. What happens?
Debug mode can only be set on a development-mode app, one created directly from a version or from staged files in the same account as the package. An app created from a release directive isn't in development mode, so the command is rejected.
“DEBUG_MODE can only be set/unset if the application is created directly from a particular version or stage”Source: docs.snowflake.com
Sources2
3.Session debug mode and its execution contexts
Session debug mode runs your statements as the app, in your current session only. Objects you create are owned by the app, and CURRENT_ROLE() returns the app's name. It has the same requirements as debug mode: a development-mode app in the same account as its package, OWNERSHIP on the app and DEVELOP on the package. It applies to one app at a time, so end it before you start it for another app.
| Execution mode | Privileges your statements use | Use it to test |
|---|---|---|
| AS_APPLICATION (default) | The privileges the app has in a consumer account | What the running app can do |
| AS_SETUP_SCRIPT | The privileges the setup script has during install or upgrade | Statements you plan to put in the setup script |
SELECT SYSTEM$BEGIN_DEBUG_APPLICATION('hello_snowflake_app', 'AS_SETUP_SCRIPT');SYSTEM$GET_DEBUG_STATUS() shows which context you are in. It returns the instance name, the domain and the execution_mode, or {} when session debug mode is off. SYSTEM$END_DEBUG_APPLICATION() ends it. Debug mode is checked differently: look at the debug_mode row of DESC APPLICATION. IS_DEV_MODE reports neither mode, only how the app was created. Called from your own session, it returns NULL unless session debug mode is on.
Testing locally also lets you turn off redaction. Inside an app, provider details are normally hidden from the query profile and query history. On a development-mode app you can set DISABLE_APPLICATION_REDACTION = TRUE to see them while you test, and set it back to FALSE when you're done. Session debug mode shows the app's own objects and data unredacted as well, including SHOW APPLICATIONS and DESCRIBE APPLICATION output.
Checkpoint 3 of 4· Check yourself
You want to confirm that a new statement will succeed with the privileges the setup script holds during install, before you publish. Which call do you make?
The default AS_APPLICATION context mimics the app in a consumer account, which is not what the setup script runs with. Only AS_SETUP_SCRIPT uses the setup script's privileges. Debug mode keeps your own role, and disabling redaction changes only what the query profile shows.
“AS_SETUP_SCRIPT: the privileges that the setup script has when it runs during install or upgrade.”Source: docs.snowflake.com
Sources2
4.Role-aware Streamlit UIs and environment.yml
A Streamlit app inside a Native App is created by the setup script, and consumers reach it through application roles like any other object. The setup script names the directory and main file. It then grants USAGE on both the schema and the Streamlit object to an application role. If either grant is missing, the UI is invisible to consumers, and debug mode will reveal that.
CREATE OR REPLACE STREAMLIT app_schema.my_test_app_na
FROM '/code_artifacts/streamlit'
MAIN_FILE = '/streamlit_app.py';
GRANT USAGE ON SCHEMA APP_SCHEMA TO APPLICATION ROLE app_public;
GRANT USAGE ON STREAMLIT APP_SCHEMA.MY_TEST_APP_NA TO APPLICATION ROLE app_public;Once inside the UI, users can be treated differently. The Streamlit code calls IS_APPLICATION_ROLE_IN_SESSION and shows or hides a feature based on the result, for example an admin panel only for holders of an admin role. The function checks the consumer's current session, works only when called from within a Native App, and takes a single role name. It does not return TRUE when the app itself is the caller, because the app owns its application roles but is not granted them. A test of the gated UI therefore needs a consumer-side role, not a session-debug session running as the app.
SELECT IS_APPLICATION_ROLE_IN_SESSION('ANALYST');Python packages for a Streamlit app on a warehouse runtime are managed by conda and declared in environment.yml. They are installed from the Snowflake Anaconda Channel, which includes Python packages and some non-Python system libraries. Pick Streamlit versions from the supported list rather than anything the channel happens to carry. Placement matters in an app: environment.yml must be in the same directory as the Streamlit main file, such as code_artifacts/streamlit/ next to streamlit_app.py. Put it anywhere else in the package and it is ignored.
Checkpoint 4 of 4· Fill the gap
Complete the call a Streamlit page makes to test whether the viewer holds a given application role in their current session.
SELECT ? ('ANALYST');IS_APPLICATION_ROLE_IN_SESSION checks application roles in the consumer's session. IS_ROLE_IN_SESSION covers account roles and IS_DATABASE_ROLE_IN_SESSION covers database roles.
Source: docs.snowflake.comPractise it for real
Use debug mode on a development-mode app to find an ungranted table, then fix the grant in the setup script.
1.Put the setup script that creates core.config without a grant on your stage, and install hello_snowflake_app from those staged files.
Why: An app created from staged files is in development mode, which debug mode requires.
You should see: The app installs and the setup script creates app_public and core.config.
2.Run SHOW TABLES IN APPLICATION hello_snowflake_app; and then SELECT * FROM hello_snowflake_app.core.config;
Why: This shows the app the way a consumer holding the app roles sees it.
You should see: SHOW TABLES returns no rows and the SELECT fails with error 002003.
3.Run ALTER APPLICATION hello_snowflake_app SET DEBUG_MODE = TRUE; and repeat both statements.
Why: Debug mode shows every object, so anything that appears only now is missing a grant.
You should see: CONFIG is listed and the query succeeds.
4.Add GRANT SELECT ON TABLE core.config TO APPLICATION ROLE app_public; to the setup script, upload it, and run ALTER APPLICATION ... UPGRADE USING the stage.
Why: The fix belongs in the setup script so that every consumer install gets it.
You should see: The upgrade completes and the setup script runs again.
5.Set DEBUG_MODE = FALSE and repeat the SELECT.
Why: Turning debug mode off confirms the consumer-facing view, not your debug view.
You should see: The query succeeds with debug mode off.
Stuck? Get a nudge
If SET DEBUG_MODE fails with 093039, the app was not created from a stage or version in the same account as its application package.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“A provider creates or upgrades an app when testing the application package.”
↩︎ Installing a test app in development mode“An application role created within the setup script is automatically granted to the role owning the app.”
↩︎ Installing a test app in development mode - 2.https://docs.snowflake.com/en/developer-guide/native-apps/installing-testing-applicationOfficial docs
“requires the app to be created based on a specific version or based on files located on a stage”
↩︎ Installing a test app in development mode“Debug mode is a property of the app, so it stays on in every session until you turn it off.”
↩︎ Debug mode: seeing what the setup script hid“With debug mode off, SHOW TABLES IN APPLICATION hello_snowflake_app; returns no rows, and querying the table fails:”
↩︎ Debug mode: seeing what the setup script hid“Session debug mode runs your statements as the app, in the current session only.”
↩︎ Session debug mode and its execution contexts“AS_SETUP_SCRIPT: the privileges that the setup script has when it runs during install or upgrade.”
↩︎ Session debug mode and its execution contexts“When testing an app locally, you can disable redaction of provider data from the query profile and query history.”
↩︎ Session debug mode and its execution contexts“Objects that you create in debug mode are owned by your current role, not by the app.”
↩︎ Exam trap 1“IS_DEV_MODE reports how the app was created.”
↩︎ Exam trap 2“Objects that you create in debug mode are owned by your current role, not by the app.”
↩︎ Prediction“DEBUG_MODE can only be set/unset if the application is created directly from a particular version or stage”
↩︎ Checkpoint - 3.
“Consumers must manually grant these privileges when installing or upgrading an app.”
↩︎ Installing a test app in development mode“For example, the following privileges aren’t automatically granted to the app: MANAGE WAREHOUSES”
↩︎ Checkpoint - 4.
“This function is only supported when called from within a Snowflake Native App.”
↩︎ Role-aware Streamlit UIs and environment.yml“The function does not return TRUE when the application calls the function because application roles are owned but not granted to the app.”
↩︎ Exam trap 3 - 5.
“The environment.yml file must be at the same level as your main file of your Streamlit app.”
↩︎ Role-aware Streamlit UIs and environment.yml - 6.https://docs.snowflake.com/en/developer-guide/streamlit/app-development/dependency-managementOfficial docs
“Dependencies are installed from the Snowflake Anaconda Channel, which includes both Python packages and some non-Python system libraries.”
↩︎ Role-aware Streamlit UIs and environment.yml