AttributeError: 'StreamlitPage' object has no attribute '_default' When running from python

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed? Locally
  2. Share the full text of the error message (not a screenshot).
Traceback (most recent call last):
  File "/Users/charles/Developer/Kraken/inksacio/src/inksacio/apps/data_observability/freshness/app.py", line 8, in <module>
    navigation.set_navigation()
  File "/Users/charles/Developer/Kraken/inksacio/src/inksacio/apps/data_observability/freshness/navigation.py", line 8, in set_navigation
    pg = st.navigation(
  File "/Users/charles/.local/share/virtualenvs/freshness-5iWkCm3l/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 408, in wrapped_func
    result = non_optional_func(*args, **kwargs)
  File "/Users/charles/.local/share/virtualenvs/freshness-5iWkCm3l/lib/python3.10/site-packages/streamlit/commands/navigation.py", line 178, in navigation
    if page._default:
AttributeError: 'StreamlitPage' object has no attribute '_default'
  1. Share the Streamlit and Python versions.
    Python 3.10.13
    streamlit = “==1.37.1”

Hello ! I am moving my app to the new st.navigation and on normal invocation it is working fine. When I try to schedule it though, I get AttributeError: ‘StreamlitPage’ object has no attribute ‘_default’
The scheduling is done by calling os.system(f"python {app_file} {cache_cli_arg}") from one of the pages while the app.py itself is just

import streamlit as st

from blabla import navigation

st.set_page_config(page_icon=":flag-jp:", layout="wide")

navigation.set_navigation()

which is just

pg = st.navigation(pages,)
pg.run()

Any idea how I can fix this ? Do i need to set a default page somewhere ?

How exactly is pages defined?

st.navigation should assume that the first page is the default page, unless one of the pages has been created with default=True (see st.Page - Streamlit Docs).

This doesn’t look right. What are you trying to schedule here? What are the values of app_file and cache_cli_arg when you make that call?

Also, that could potentially call a different python or run it in a different environment. Consider using sys.executable instead of "python".

Its a list of st.Page objects, and currently there is no default set up using default=True

the app file is the default/main app.py that is used as the root of the project. Basically I have an app with multiple pages, and one one of the pages there is a query that I want to schedule to run every hour, so that I can use its output to emit some metrics. If there is a better way to achieve that I am happy to change the current setup

If app_file is the name of a streamlit application, you cannot run it like that. You need to use something like this

os.system(f"streamlit run {app_file} {cache_cli_arg}")

or maybe

os.system(f"{sys.executable} -m streamlit run {app_file} {cache_cli_arg}")

But that would launch a new instance of your application, which I don’t think is what you want.