diff --git a/.flaskenv b/.flaskenv index 49bf390fb3db..5ed928d76a51 100644 --- a/.flaskenv +++ b/.flaskenv @@ -15,4 +15,4 @@ # limitations under the License. # FLASK_APP="superset.app:create_app()" -FLASK_ENV="development" +FLASK_DEBUG=true diff --git a/.github/workflows/superset-applitool-cypress.yml b/.github/workflows/superset-applitool-cypress.yml index 7222ed17d41c..6707fb05b7fe 100644 --- a/.github/workflows/superset-applitool-cypress.yml +++ b/.github/workflows/superset-applitool-cypress.yml @@ -28,7 +28,7 @@ jobs: browser: ["chrome"] node: [16] env: - FLASK_ENV: development + SUPERSET_ENV: development SUPERSET_CONFIG: tests.integration_tests.superset_test_config SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset PYTHONPATH: ${{ github.workspace }} diff --git a/.github/workflows/superset-e2e.yml b/.github/workflows/superset-e2e.yml index e1b090a5f399..e9ef9a495346 100644 --- a/.github/workflows/superset-e2e.yml +++ b/.github/workflows/superset-e2e.yml @@ -26,7 +26,7 @@ jobs: containers: [1, 2, 3] browser: ["chrome"] env: - FLASK_ENV: development + SUPERSET_ENV: development SUPERSET_CONFIG: tests.integration_tests.superset_test_config SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset PYTHONPATH: ${{ github.workspace }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e36363a7a548..8c5d60f23682 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -453,7 +453,7 @@ superset load-examples # Start the Flask dev web server from inside your virtualenv. # Note that your page may not have CSS at this point. # See instructions below how to build the front-end assets. -FLASK_ENV=development superset run -p 8088 --with-threads --reload --debugger +superset run -p 8088 --with-threads --reload --debugger --debug ``` Or you can install via our Makefile @@ -477,7 +477,7 @@ $ make pre-commit via `.flaskenv`, however if needed, it should be set to `superset.app:create_app()`** If you have made changes to the FAB-managed templates, which are not built the same way as the newer, React-powered front-end assets, you need to start the app without the `--with-threads` argument like so: -`FLASK_ENV=development superset run -p 8088 --reload --debugger` +`superset run -p 8088 --reload --debugger --debug` #### Dependencies @@ -518,7 +518,7 @@ def FLASK_APP_MUTATOR(app): Then make sure you run your WSGI server using the right worker type: ```bash -FLASK_ENV=development gunicorn "superset.app:create_app()" -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 127.0.0.1:8088 --reload +gunicorn "superset.app:create_app()" -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 127.0.0.1:8088 --reload ``` You can log anything to the browser console, including objects: @@ -603,7 +603,7 @@ So a typical development workflow is the following: 1. [run Superset locally](#flask-server) using Flask, on port `8088` — but don't access it directly,
```bash # Install Superset and dependencies, plus load your virtual environment first, as detailed above. - FLASK_ENV=development superset run -p 8088 --with-threads --reload --debugger + superset run -p 8088 --with-threads --reload --debugger --debug ``` 2. in parallel, run the Webpack dev server locally on port `9000`,
```bash @@ -922,7 +922,7 @@ For debugging locally using VSCode, you can configure a launch configuration fil "module": "flask", "env": { "FLASK_APP": "superset", - "FLASK_ENV": "development" + "SUPERSET_ENV": "development" }, "args": [ "run", diff --git a/Dockerfile b/Dockerfile index 0745294b4537..7ae77790a4e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ FROM python:${PY_VER} AS lean ENV LANG=C.UTF-8 \ LC_ALL=C.UTF-8 \ - FLASK_ENV=production \ + SUPERSET_ENV=production \ FLASK_APP="superset.app:create_app()" \ PYTHONPATH="/app/pythonpath" \ SUPERSET_HOME="/app/superset_home" \ diff --git a/RELEASING/from_tarball_entrypoint.sh b/RELEASING/from_tarball_entrypoint.sh index 27b247eb72fe..fa01592b2100 100755 --- a/RELEASING/from_tarball_entrypoint.sh +++ b/RELEASING/from_tarball_entrypoint.sh @@ -38,5 +38,5 @@ superset init # Loading examples superset load-examples --force -FLASK_ENV=development FLASK_APP="superset.app:create_app()" \ +SUPERSET_ENV=development FLASK_APP="superset.app:create_app()" \ flask run -p 8088 --with-threads --reload --debugger --host=0.0.0.0 diff --git a/UPDATING.md b/UPDATING.md index d6c6f71668fe..984e20e27c2f 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -31,6 +31,12 @@ assists people when migrating to a new version. - [23652](https://github.com/apache/superset/pull/23652): Enables GENERIC_CHART_AXES feature flag by default. - [23226](https://github.com/apache/superset/pull/23226): Migrated endpoint `/estimate_query_cost/` to `/api/v1/sqllab/estimate/`. Corresponding permissions are can estimate query cost on SQLLab. Make sure you add/replace the necessary permissions on any custom roles you may have. - [23890](https://github.com/apache/superset/pull/23890): Removes Python 3.8 support. +- [24404](https://github.com/apache/superset/pull/24404): FLASK_ENV is getting + deprecated, we recommend using SUPERSET_ENV and reviewing your + config for ENVIRONMENT_TAG_CONFIG, which enables adding a tag in the navbar to + make it more clear which envrionment your are in. + `SUPERSET_ENV=production` and `SUPERSET_ENV=development` are the two + supported switches based on the default config. ### Breaking Changes diff --git a/docker/.env b/docker/.env index 5cb16d611a14..619c7d876031 100644 --- a/docker/.env +++ b/docker/.env @@ -39,7 +39,7 @@ PYTHONPATH=/app/pythonpath:/app/docker/pythonpath_dev REDIS_HOST=redis REDIS_PORT=6379 -FLASK_ENV=development +SUPERSET_ENV=development SUPERSET_ENV=development SUPERSET_LOAD_EXAMPLES=yes CYPRESS_CONFIG=false diff --git a/docker/.env-non-dev b/docker/.env-non-dev index 726b0bb167bf..cf4764221c28 100644 --- a/docker/.env-non-dev +++ b/docker/.env-non-dev @@ -39,7 +39,7 @@ PYTHONPATH=/app/pythonpath:/app/docker/pythonpath_dev REDIS_HOST=redis REDIS_PORT=6379 -FLASK_ENV=production +SUPERSET_ENV=production SUPERSET_ENV=production SUPERSET_LOAD_EXAMPLES=yes SUPERSET_SECRET_KEY=TEST_NON_DEV_SECRET diff --git a/docs/docs/contributing/local-backend.mdx b/docs/docs/contributing/local-backend.mdx index 5056f167369d..e8dc5403eb55 100644 --- a/docs/docs/contributing/local-backend.mdx +++ b/docs/docs/contributing/local-backend.mdx @@ -42,7 +42,7 @@ superset load-examples # Start the Flask dev web server from inside your virtualenv. # Note that your page may not have CSS at this point. -FLASK_ENV=development superset run -p 8088 --with-threads --reload --debugger +superset run -p 8088 --with-threads --reload --debugger --debug ``` Or you can install via our Makefile @@ -66,7 +66,7 @@ make pre-commit via `.flaskenv`, however if needed, it should be set to `superset.app:create_app()`** If you have made changes to the FAB-managed templates, which are not built the same way as the newer, React-powered front-end assets, you need to start the app without the `--with-threads` argument like so: -`FLASK_ENV=development superset run -p 8088 --reload --debugger` +`superset run -p 8088 --reload --debugger --debug` #### Dependencies @@ -93,7 +93,7 @@ def FLASK_APP_MUTATOR(app): Then make sure you run your WSGI server using the right worker type: ```bash -FLASK_ENV=development gunicorn "superset.app:create_app()" -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 127.0.0.1:8088 --reload +SUPERSET_ENV=development gunicorn "superset.app:create_app()" -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 127.0.0.1:8088 --reload ``` You can log anything to the browser console, including objects: diff --git a/superset/config.py b/superset/config.py index d62003991a8f..b3e4121cf8a0 100644 --- a/superset/config.py +++ b/superset/config.py @@ -246,7 +246,7 @@ def _try_json_readsha(filepath: str, length: int) -> str | None: ] # Whether to run the web server in debug mode or not -DEBUG = os.environ.get("FLASK_ENV") == "development" +DEBUG = os.environ.get("FLASK_DEBUG") FLASK_USE_RELOAD = True # Enable profiling of Python calls. Turn this on and append ``?_instrument=1`` @@ -1507,8 +1507,12 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument # Configuration for environment tag shown on the navbar. Setting 'text' to '' will hide the tag. # 'color' can either be a hex color code, or a dot-indexed theme color (e.g. error.base) ENVIRONMENT_TAG_CONFIG = { - "variable": "FLASK_ENV", + "variable": "SUPERSET_ENV", "values": { + "debug": { + "color": "error.base", + "text": "flask-debug", + }, "development": { "color": "error.base", "text": "Development", diff --git a/superset/views/base.py b/superset/views/base.py index e66fea0a48c2..3a45faf4bc19 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -333,6 +333,30 @@ def render_app_template(self) -> FlaskResponse: ) +def get_environment_tag() -> dict[str, Any]: + # Whether flask is in debug mode (--debug) + debug = appbuilder.app.config["DEBUG"] + + # Getting the configuration option for ENVIRONMENT_TAG_CONFIG + env_tag_config = appbuilder.app.config["ENVIRONMENT_TAG_CONFIG"] + + # These are the predefined templates define in the config + env_tag_templates = env_tag_config.get("values") + + # This is the environment variable name from which to select the template + # default is SUPERSET_ENV (from FLASK_ENV in previous versions) + env_envvar = env_tag_config.get("variable") + + # this is the actual name we want to use + env_name = os.environ.get(env_envvar) + + if not env_name or env_name not in env_tag_templates.keys(): + env_name = "debug" if debug else None + + env_tag = env_tag_templates.get(env_name) + return env_tag or {} + + def menu_data(user: User) -> dict[str, Any]: menu = appbuilder.menu.get_data() @@ -346,17 +370,6 @@ def menu_data(user: User) -> dict[str, Any]: if callable(brand_text): brand_text = brand_text() build_number = appbuilder.app.config["BUILD_NUMBER"] - try: - environment_tag = ( - appbuilder.app.config["ENVIRONMENT_TAG_CONFIG"]["values"][ - os.environ.get( - appbuilder.app.config["ENVIRONMENT_TAG_CONFIG"]["variable"] - ) - ] - or {} - ) - except KeyError: - environment_tag = {} return { "menu": menu, @@ -367,7 +380,7 @@ def menu_data(user: User) -> dict[str, Any]: "tooltip": appbuilder.app.config["LOGO_TOOLTIP"], "text": brand_text, }, - "environment_tag": environment_tag, + "environment_tag": get_environment_tag(), "navbar_right": { # show the watermark if the default app icon has been overridden "show_watermark": ("superset-logo-horiz" not in appbuilder.app_icon),