question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] FlaskDynaconf doesn't handle __contains__

See original GitHub issue

Describe the bug

Checking key in app.config returns False if the key is only set on app.config after the extension is initialized. However, accessing app.config[key] still works. If the key was set before initializing the extension, or through an env var, it correctly reports True.

This is important for extensions like Flask-SQLAlchemy. It checks if the key SQLALCHEMY_DATABASE_URI is set and shows a warning otherwise, incorrectly in this case.

To Reproduce

from dynaconf import FlaskDynaconf
from flask import Flask

dynaconf = FlaskDynaconf()
app = Flask(__name__)
dynaconf.init_app(app)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"

print("SQLALCHEMY_DATABASE_URI" in app.config)  # False, should be True
print(app.config["SQLALCHEMY_DATABASE_URI"])  # sqlite:///app.db

Expected behavior

The in operator reports the correct result when a key is set after calling init_app().

Environment (please complete the following information):

  • OS: Linux/Arch
  • Dynaconf 3.1.2
  • Flask 1.1.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rochacbrunocommented, Mar 8, 2021

passing CI I will do the hotfix release.

1reaction
damian-tcommented, Feb 17, 2021

Any update on this (https://github.com/rochacbruno/dynaconf/pull/502)? I would love to see this in the next release

Read more comments on GitHub >

github_iconTop Results From Across the Web

[bug] FlaskDynaconf doesn't handle __contains__ #501 - GitHub
Describe the bug Checking key in app.config returns False if the key is only set on app.config after the extension is initialized.
Read more >
Advanced usage - Dynaconf - 3.1.11
BAR) AttributeError: settings object has no attribute 'BAR'. Then you can use from_env : ... src.py that has a Flask application factory.
Read more >
Pedantic Configuration Management with Pydantic
Mitigating Python application's configuration madness with Pydantic.
Read more >
How to Write a Configuration file in Python | by Xiaoxu Gao
The most common configuration includes credentials to the database or an ... Configureparser doesn't guess datatypes in the config file, ...
Read more >
Settings and Environment Variables - FastAPI
These environment variables can only handle text strings, as they are external to ... But a dotenv file doesn't really have to have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found