-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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(refactor): load configuration and merge recursively #15405
chore(refactor): load configuration and merge recursively #15405
Conversation
Codecov Report
@@ Coverage Diff @@
## master #15405 +/- ##
==========================================
- Coverage 77.23% 77.02% -0.22%
==========================================
Files 975 975
Lines 50615 50630 +15
Branches 6212 6212
==========================================
- Hits 39094 38996 -98
- Misses 11314 11427 +113
Partials 207 207
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
this will support a reacher config structure in #15296
* refactor load configuration * refactor init configuration to enable recursive merge * Update config.py * Update app.py * fix lint and black issue
@ofekisr currently my RESULTS_BACKEND = RedisCache(host="localhost", port=6379, key_prefix="superset_results") And it failes to run because
|
def init_config() -> Dict[Any, Any]: | ||
config = convert_to_dict(load_default_config()) | ||
override_conf = convert_to_dict(load_override_config()) | ||
return merge(config, override_conf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bringing a new dependency (pydash) just to merge two dicts here is overkill. Why not just use dict.update
?
I'm also not sure if a recursive merge is the right strategy here. If we have:
# superset/config.py
a = {"b": "c"}
And I create a custom config:
# superset_config.py
a = {"d": "e"}
This would result in the following configuration:
{'a': {'b': 'c', 'd': 'e'}}
Which is probably not what we want.
As a concrete example, we currently have languages configured in superset/config.py
:
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"es": {"flag": "es", "name": "Spanish"},
"it": {"flag": "it", "name": "Italian"},
"fr": {"flag": "fr", "name": "French"},
"zh": {"flag": "cn", "name": "Chinese"},
"ja": {"flag": "jp", "name": "Japanese"},
"de": {"flag": "de", "name": "German"},
"pt": {"flag": "pt", "name": "Portuguese"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
"ru": {"flag": "ru", "name": "Russian"},
"ko": {"flag": "kr", "name": "Korean"},
"sl": {"flag": "si", "name": "Slovenian"},
}
If I want to have just Portuguese in my Superset instance I would add to my config:
LANGUAGES = {
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
}
But the merge
would bring back all languages.
@ofekisr @amitmiran137 @betodealmeida @villebro I'm all for standardizing the configuration import logic but why don't we simply use the recommended Flask pattern , i.e., app = Flask(__name__)
app.config.from_object("superset.config")
app.config.from_envvar("SUPERSET_CONFIG_PATH", silent=True) instead of writing our own import/merge logic? |
@ofekisr @amitmiran137 this updated logic breaks existing config functionality, specifically where callable configuration references other configuration variables: i.e., locally overriding the Note I'm supportive of the general direction of this PR, especially given the previous logic is atypical from a Flask perspective, however the regression needs to be addressed by either i) amending the logic or ii) reverting this PR (alongside @betodealmeida's and @villebro's fixes). |
@john-bodley I have PR reverting the changes: #15558 I think we need to evaluate this better, since we already tried to fix it twice and it's still breaking our deployments. |
(cherry picked from commit 83be06d)
* refactor load configuration * refactor init configuration to enable recursive merge * Update config.py * Update app.py * fix lint and black issue
* refactor load configuration * refactor init configuration to enable recursive merge * Update config.py * Update app.py * fix lint and black issue
* refactor load configuration * refactor init configuration to enable recursive merge * Update config.py * Update app.py * fix lint and black issue
SUMMARY
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION