[bug] FlaskDynaconf doesn't handle __contains__
See original GitHub issueDescribe 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:
- Created 3 years ago
- Reactions:3
- Comments:10 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
passing CI I will do the hotfix release.
Any update on this (https://github.com/rochacbruno/dynaconf/pull/502)? I would love to see this in the next release