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

chore: Refactor command exceptions #24117

Merged

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented May 18, 2023

SUMMARY

Whilst debugging an issue I came across a frequently repeated pattern:

if exceptions:
    exception = AnnotationInvalidError()
    exception.add_list(exceptions)
    raise exception

These exceptions are derived from the CommandInvalidError class which included the add and add_list methods and had no way of adding the exceptions when constructing the error. To adhere to the DRY principle this PR performs the following:

  1. Renames add to append—akin to list.append.
  2. Renames add_list to extend—akin to list.extend.
  3. Add the ability to specify the exceptions in the __init__ method.

where the later means that the snippet of code above reduces to,

if exceptions:
    raise AnnotationInvalidError(exceptions=exceptions)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

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

@john-bodley john-bodley marked this pull request as ready for review May 18, 2023 15:44
@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Merging #24117 (d75d1e1) into master (2222073) will decrease coverage by 0.01%.
The diff coverage is 81.25%.

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

@@            Coverage Diff             @@
##           master   #24117      +/-   ##
==========================================
- Coverage   68.30%   68.29%   -0.01%     
==========================================
  Files        1952     1952              
  Lines       75432    75388      -44     
  Branches     8191     8191              
==========================================
- Hits        51521    51486      -35     
+ Misses      21807    21798       -9     
  Partials     2104     2104              
Flag Coverage Δ
hive 53.23% <9.37%> (+0.06%) ⬆️
mysql 78.95% <78.12%> (+<0.01%) ⬆️
postgres 79.02% <78.12%> (+<0.01%) ⬆️
presto 53.16% <9.37%> (+0.06%) ⬆️
python 82.81% <81.25%> (+<0.01%) ⬆️
sqlite 77.55% <75.00%> (+0.01%) ⬆️
unit 53.14% <25.00%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
superset/commands/importers/v1/assets.py 88.09% <0.00%> (+2.04%) ⬆️
superset/tags/commands/create.py 78.78% <0.00%> (+4.50%) ⬆️
superset/tags/commands/delete.py 75.43% <0.00%> (+4.94%) ⬆️
superset/dashboards/commands/update.py 85.93% <50.00%> (+2.11%) ⬆️
superset/commands/exceptions.py 93.84% <87.50%> (-1.54%) ⬇️
...t/annotation_layers/annotations/commands/create.py 85.36% <100.00%> (-0.69%) ⬇️
...t/annotation_layers/annotations/commands/update.py 87.23% <100.00%> (-0.53%) ⬇️
superset/annotation_layers/commands/create.py 88.88% <100.00%> (-0.77%) ⬇️
superset/annotation_layers/commands/update.py 90.90% <100.00%> (-0.52%) ⬇️
superset/charts/commands/create.py 91.66% <100.00%> (-0.34%) ⬇️
... and 12 more

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

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

I really like it! thanks for doing this

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Much cleaner!

@john-bodley john-bodley merged commit 8b4222f into apache:master May 19, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 8, 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 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants