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

Many settings as defined in settings.py do not respect the documented environment variables #2578

Closed
glennmatthews opened this issue Oct 5, 2022 · 1 comment · Fixed by #2664
Assignees
Labels
type: bug Something isn't working as expected

Comments

@glennmatthews
Copy link
Contributor

Environment

  • Nautobot version (Docker tag too if applicable): 1.4.5
  • Python version: any
  • Database platform, version: any
  • Middleware(s): n/a

Steps to Reproduce

  1. Use a minimal, stripped-down nautobot_config.py, rather than one containing all optional settings like the nautobot/core/templates/nautobot_config.py.j2 template does.
  2. Attempt to influence various optional settings by setting environment variables for the Nautobot process, e.g. NAUTOBOT_DEBUG=True

Expected Behavior

Environment variables should be respected as documented.

Observed Behavior

Many environment variables are not respected by the defaults defined in settings.py, only the overrides for these settings in nautobot_config.py.j2 respect environment variables. Related: #2574. The below list may not be comprehensive:

  • CACHEOPS_DEFAULTS / NAUTOBOT_CACHEOPS_DEFAULTS
  • CACHEOPS_ENABLED / NAUTOBOT_CACHEOPS_ENABLED
  • CACHEOPS_REDIS / NAUTOBOT_CACHEOPS_REDIS
  • CORS_ALLOW_ALL_ORIGINS / NAUTOBOT_CORS_ALLOW_ALL_ORIGINS
  • DEBUG / NAUTOBOT_DEBUG
  • DISABLE_PREFIX_LIST_HIERARCHY / NAUTOBOT_DISABLE_PREFIX_LIST_HIERARCHY (making this inherit from a variable by default would possibly break our Constance config though)
  • ENFORCE_GLOBAL_UNIQUE / NAUTOBOT_ENFORCE_GLOBAL_UNIQUE
  • MAINTENANCE_MODE / NAUTOBOT_MAINTENANCE_MODE
  • METRICS_ENABLED / NAUTOBOT_METRICS_ENABLED
  • SESSION_COOKIE_AGE / NAUTOBOT_SESSION_COOKIE_AGE
  • SESSION_FILE_PATH / NAUTOBOT_SESSION_FILE_PATH
  • STRICT_FILTERING / NAUTOBOT_STRICT_FILTERING
  • TIME_ZONE / NAUTOBOT_TIME_ZONE, as well as all of the related time/date format variables

Solution should probably be to just strip down nautobot_config.py.j2 and move the environment variable checks directly into settings.py.

This also relates to #1150.

@jathanism
Copy link
Contributor

jathanism commented Oct 5, 2022

  • METRICS_ENABLED / NAUTOBOT_METRICS_ENABLED

This one can't easily be set as an environment variable because it's a "magic" setting that is interpreted.

The magic variable is processed inside of nautobot.core.cli._configure_settings, so if an environment variable were to be read, it would have to be done so in this code block:

    # If metrics are enabled and postgres is the backend, set the driver to the
    # one provided by django-prometheus.
    if settings.METRICS_ENABLED and "postgres" in settings.DATABASES["default"]["ENGINE"]:
        settings.DATABASES["default"]["ENGINE"] = "django_prometheus.db.backends.postgresql"

I would rather us eliminate this setting entirely in exchange for just having users explicitly set the metrics backend by just setting this in nautobot_config.py:

DATABASES["default"]["ENGINE"] = "django_prometheus.db.backends.postgresql"

Obviously, this latter approach would require revising our documentation on enabling metrics.

@glennmatthews glennmatthews self-assigned this Oct 18, 2022
glennmatthews added a commit that referenced this issue Oct 20, 2022
glennmatthews added a commit that referenced this issue Oct 25, 2022
…ttings.py`, remove `nautobot_config.append.py`, etc. (#2664)

* WIP fix for #2578

* Multiple updates:

- Move logging defaults to settings.py for consistency between virtualenv and Docker deployments
- Remove docker/nautobot_config.append.py as no longer needed to customize Docker
- Simplify development/nautobot_config.py
- Simplify nautobot/core/tests/nautobot_config.py
- Update documentation
- Add documentation about django-cryptography bug while I'm touching related docs

* Fix logging defaults for DEBUG=True case

* flake8

* Update logging info

* Update template to better match documentation

* Change fragments
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
2 participants