Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate FLASK_ENV and improve conf.ENVIRONMENT_TAG_CONFIG #24404

Merged
merged 10 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.
#
FLASK_APP="superset.app:create_app()"
FLASK_ENV="development"
FLASK_DEBUG=true
2 changes: 1 addition & 1 deletion .github/workflows/superset-applitool-cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/superset-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion RELEASING/from_tarball_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/.env-non-dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/contributing/local-backend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down Expand Up @@ -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",
Expand Down
37 changes: 25 additions & 12 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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),
Expand Down
Loading