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

fix: catch error when masking encrypted extra is none #21570

Merged
merged 3 commits into from
Oct 3, 2022

Conversation

eschutho
Copy link
Member

SUMMARY

When masking/unmasking the encrypted extra field, this change allows imported dbs to have a blank encrypted extra field, because they are not imported.

TESTING INSTRUCTIONS

Import a database and try to edit it in the database connection modal.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

try:
config = json.loads(encrypted_extra)
except json.JSONDecodeError:
config = json.loads(encrypted_extra) # type:ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

@betodealmeida the other option here would be to have a default value if encrypted_extra is None, but I opted for including it in the try/catch since it already existed. Of course, this requires the type ignores because the linter isn't aware of the try/except.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good! Alternatively I think this would also work:

def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
    if encrypted_extra is None:
        return encrypted_extra

    try:
        ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Yeah I think it looks better this way without the type ignores. I also left the TypeError in the except block just in case.

@codecov
Copy link

codecov bot commented Sep 23, 2022

Codecov Report

Merging #21570 (f0556ce) into master (2224ebe) will decrease coverage by 11.37%.
The diff coverage is 81.81%.

❗ Current head f0556ce differs from pull request most recent head ad122fc. Consider uploading reports for the commit ad122fc to get more accurate results

@@             Coverage Diff             @@
##           master   #21570       +/-   ##
===========================================
- Coverage   66.67%   55.30%   -11.38%     
===========================================
  Files        1793     1794        +1     
  Lines       68523    68642      +119     
  Branches     7281     7281               
===========================================
- Hits        45688    37960     -7728     
- Misses      20971    28818     +7847     
  Partials     1864     1864               
Flag Coverage Δ
hive 52.91% <40.90%> (-0.18%) ⬇️
mysql ?
postgres ?
presto 52.81% <40.90%> (-0.18%) ⬇️
python 57.90% <81.81%> (-23.51%) ⬇️
sqlite ?
unit 50.93% <81.81%> (-0.14%) ⬇️

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

Impacted Files Coverage Δ
superset/models/core.py 79.24% <71.42%> (-10.97%) ⬇️
superset/db_engine_specs/bigquery.py 54.35% <75.00%> (-27.32%) ⬇️
superset/db_engine_specs/base.py 76.11% <100.00%> (-13.47%) ⬇️
superset/db_engine_specs/gsheets.py 77.16% <100.00%> (+1.76%) ⬆️
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/key_value/commands/update.py 0.00% <0.00%> (-88.89%) ⬇️
superset/key_value/commands/delete.py 0.00% <0.00%> (-85.30%) ⬇️
superset/key_value/commands/delete_expired.py 0.00% <0.00%> (-80.77%) ⬇️
superset/dashboards/commands/importers/v0.py 15.62% <0.00%> (-76.25%) ⬇️
superset/datasets/commands/update.py 25.00% <0.00%> (-69.05%) ⬇️
... and 293 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

A few code smell nits

superset/db_engine_specs/base.py Outdated Show resolved Hide resolved
tests/unit_tests/db_engine_specs/test_bigquery.py Outdated Show resolved Hide resolved
@yousoph
Copy link
Member

yousoph commented Sep 26, 2022

/testenv up

@github-actions
Copy link
Contributor

@yousoph Ephemeral environment spinning up at http://35.91.149.182:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Thanks for catching and fixing this!

try:
config = json.loads(encrypted_extra)
except json.JSONDecodeError:
config = json.loads(encrypted_extra) # type:ignore
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good! Alternatively I think this would also work:

def mask_encrypted_extra(cls, encrypted_extra: Optional[str]) -> Optional[str]:
    if encrypted_extra is None:
        return encrypted_extra

    try:
        ...

@eschutho eschutho merged commit ef78ec6 into apache:master Oct 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

Ephemeral environment shutdown and build artifacts deleted.

sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Oct 3, 2022
@eschutho eschutho deleted the elizabeth/fix-big-query-extra branch October 21, 2022 20:59
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants