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

feat(config): load config with hybrid strategies #15447

Closed
wants to merge 4 commits into from

Conversation

ofekisr
Copy link
Contributor

@ofekisr ofekisr commented Jun 29, 2021

SUMMARY

following the latest config loading mechanism changes and breaking changes and its follow-ups fixes:

#15448
#15444
#15435

we wanted to propose a new way for two configurations files (.py) to be unioned
and to allow flexibility to choose a strategy based on the value type

Assume config.py contains (left side)
KEY1 = { ... }
KEY2 = SomeClass

and superset_config.py contains (right side)
KEY1 = { ... }
KEY2 = SomeClass

There are 5 kinds of strategies how to union those KEY - Values

  1. take_right_strategy - simple - just override
  2. override_right_as_class_strategy - will create a class with the KEY name and its fields will be what inside the right value
  3. merge_as_class_strategy - will create a class with the KEY name and its fields will be what inside the left and right value.
  4. override_right_as_dict_strategy - will create a dict and its keys-values will be what inside the right value.
  5. merge_as_dict_strategy - will create a dict and its keys-values will be what inside the left and right value.

current meta configurations

meta_union_strategy = {
(type, type): override_right_as_class_strategy,
(type, dict): override_right_as_class_strategy,
(dict, type): override_right_as_class_strategy,
(dict, dict): merge_as_dict_strategy,
(Any, Any): take_right_strategy
}

this PR will in the future enables us to :

  1. change the strategy -
  2. defines new tuple and its strategy

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

tests/initializations/configurations/meta_configurations_tests.py

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jun 29, 2021

Codecov Report

Merging #15447 (8a5d2f6) into master (727847d) will decrease coverage by 0.14%.
The diff coverage is 70.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15447      +/-   ##
==========================================
- Coverage   77.17%   77.02%   -0.15%     
==========================================
  Files         974      978       +4     
  Lines       50698    50766      +68     
  Branches     6238     6238              
==========================================
- Hits        39124    39102      -22     
- Misses      11361    11451      +90     
  Partials      213      213              
Flag Coverage Δ
hive ?
mysql 81.71% <70.27%> (-0.01%) ⬇️
postgres 81.73% <70.27%> (-0.01%) ⬇️
python 81.82% <70.27%> (-0.30%) ⬇️
sqlite 81.36% <70.27%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/initialization/configurations/loader.py 56.52% <56.52%> (ø)
...itialization/configurations/meta_configurations.py 76.47% <76.47%> (ø)
superset/initialization/configurations/__init__.py 78.26% <78.26%> (ø)
superset/app.py 84.21% <100.00%> (+20.71%) ⬆️
superset/initialization/configurations/utils.py 100.00% <100.00%> (ø)
superset/db_engines/hive.py 0.00% <0.00%> (-82.15%) ⬇️
superset/db_engine_specs/hive.py 69.20% <0.00%> (-17.21%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/db_engine_specs/presto.py 83.36% <0.00%> (-1.06%) ⬇️
superset/db_engine_specs/base.py 87.97% <0.00%> (-0.41%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 727847d...8a5d2f6. Read the comment docs.

@amitmiran137 amitmiran137 changed the title fix: load_configuration does not override feat(config): load config with hybrid strategies Jun 29, 2021
left_dict = take_conf_keys_and_convert_to_dict(left_value)
right_dict = take_conf_keys_and_convert_to_dict(right_value)
try:
return merge_dicts_recursive(left_dict, right_dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this?

Suggested change
return merge_dicts_recursive(left_dict, right_dict)
return dict(**left_dict, **right_dict)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it doesn't merge with recursive manner

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Apr 16, 2022
@stale stale bot closed this Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Inactive for >= 30 days size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants