You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2023/06/29 19:04:40 UTC
[superset] branch master updated: chore: deprecate FLASK_ENV and improve conf.ENVIRONMENT_TAG_CONFIG (#24404)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 6a8f60f9fd chore: deprecate FLASK_ENV and improve conf.ENVIRONMENT_TAG_CONFIG (#24404)
6a8f60f9fd is described below
commit 6a8f60f9fdb832bdcca1a042f6a89c8cb12a0215
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Thu Jun 29 12:04:32 2023 -0700
chore: deprecate FLASK_ENV and improve conf.ENVIRONMENT_TAG_CONFIG (#24404)
---
.flaskenv | 2 +-
.github/workflows/superset-applitool-cypress.yml | 2 +-
.github/workflows/superset-e2e.yml | 2 +-
CONTRIBUTING.md | 10 +++----
Dockerfile | 2 +-
RELEASING/from_tarball_entrypoint.sh | 2 +-
UPDATING.md | 6 ++++
docker/.env | 2 +-
docker/.env-non-dev | 2 +-
docs/docs/contributing/local-backend.mdx | 6 ++--
superset/config.py | 8 +++--
superset/views/base.py | 37 ++++++++++++++++--------
12 files changed, 52 insertions(+), 29 deletions(-)
diff --git a/.flaskenv b/.flaskenv
index 49bf390fb3..5ed928d76a 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 7222ed17d4..6707fb05b7 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 e1b090a5f3..e9ef9a4953 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 e36363a7a5..8c5d60f236 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,<br/>
```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`,<br/>
```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 a5ee4e0a71..b7732f602e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -52,7 +52,7 @@ FROM python:${PY_VER} AS lean
WORKDIR /app
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 aae08a53c4..b6a51a55d1 100755
--- a/RELEASING/from_tarball_entrypoint.sh
+++ b/RELEASING/from_tarball_entrypoint.sh
@@ -41,5 +41,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 f55102d15e..6713cbfe59 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/<int:database_id>` 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 5cb16d611a..619c7d8760 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 726b0bb167..cf4764221c 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 5056f16736..e8dc5403eb 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 4ac95925ec..e781862395 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -246,7 +246,7 @@ WTF_CSRF_EXEMPT_LIST = [
]
# 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``
@@ -1537,8 +1537,12 @@ WELCOME_PAGE_LAST_TAB: (
# 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 717efdff84..c93383c149 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -333,6 +333,30 @@ class BaseSupersetView(BaseView):
)
+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),