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: Backend Validation for Creation Method #16375

Merged

Conversation

AAfghahi
Copy link
Member

SUMMARY

This creates backend validation to make sure that a user cannot have multiple reports attached to one chart or dashboard with the respective creation method.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch 13 times, most recently from 0fa774e to cac0d0e Compare August 23, 2021 18:55
@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch 5 times, most recently from ff19f19 to 183aeb5 Compare August 24, 2021 17:06
@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch from 183aeb5 to 9826aa2 Compare August 24, 2021 17:16
@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #16375 (5d0b4eb) into master (c768941) will decrease coverage by 0.23%.
The diff coverage is 68.62%.

❗ Current head 5d0b4eb differs from pull request most recent head 148c09c. Consider uploading reports for the commit 148c09c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16375      +/-   ##
==========================================
- Coverage   76.55%   76.32%   -0.24%     
==========================================
  Files        1000     1000              
  Lines       53483    53518      +35     
  Branches     6818     6814       -4     
==========================================
- Hits        40945    40846      -99     
- Misses      12300    12434     +134     
  Partials      238      238              
Flag Coverage Δ
hive ?
mysql 81.54% <94.59%> (+0.05%) ⬆️
postgres 81.56% <94.59%> (+0.05%) ⬆️
presto ?
python 81.65% <94.59%> (-0.42%) ⬇️
sqlite 81.17% <94.59%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
superset-frontend/src/components/Modal/Modal.tsx 100.00% <ø> (ø)
...-frontend/src/components/OmniContainer/Omnibar.tsx 100.00% <ø> (ø)
...et-frontend/src/dashboard/components/Dashboard.jsx 78.84% <ø> (ø)
...rontend/src/dashboard/containers/DashboardPage.tsx 0.00% <0.00%> (ø)
...c/views/CRUD/data/database/DatabaseModal/index.tsx 44.24% <0.00%> (-0.12%) ⬇️
...dashboard/components/SliceHeaderControls/index.tsx 75.00% <33.33%> (-0.40%) ⬇️
superset/charts/commands/update.py 88.73% <50.00%> (-0.16%) ⬇️
...frontend/src/views/CRUD/alert/AlertReportModal.tsx 61.39% <58.75%> (-1.50%) ⬇️
...et-frontend/src/components/OmniContainer/index.tsx 86.95% <76.19%> (-10.11%) ⬇️
...frontend/src/components/TimezoneSelector/index.tsx 97.72% <100.00%> (-0.06%) ⬇️
... and 20 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 c768941...148c09c. Read the comment docs.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 24, 2021
@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch from e0f1436 to 95a7207 Compare August 24, 2021 21:04
@betodealmeida betodealmeida self-requested a review August 24, 2021 21:40
superset/reports/commands/create.py Show resolved Hide resolved
superset/reports/dao.py Outdated Show resolved Hide resolved
superset/reports/dao.py Outdated Show resolved Hide resolved
superset/reports/dao.py Outdated Show resolved Hide resolved
superset/reports/dao.py Show resolved Hide resolved
tests/integration_tests/reports/api_tests.py Outdated Show resolved Hide resolved
tests/integration_tests/reports/api_tests.py Outdated Show resolved Hide resolved
uri = "api/v1/report/"
rv = self.client.post(uri, json=report_schedule_data)
data = json.loads(rv.data.decode("utf-8"))
assert rv.status_code == 422
Copy link
Member

Choose a reason for hiding this comment

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

I think returning a 409 (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) makes more sense here. All you need to do is to set the attribute status = 409 in your new exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

superset/reports/commands/exceptions.py Outdated Show resolved Hide resolved
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
AAfghahi and others added 7 commits August 24, 2021 18:09
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch from 131f7db to 64b2096 Compare August 24, 2021 22:16
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.

Looks great!

"""

def __init__(self) -> None:
status = 409
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this should be on the class, not inside __init__:

class ReportScheduleCreationMethodUniquenessValidationError(ValidationError):
    status = 409

    def __init__(self) -> None:
       super().__init__(...)

@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch from 64b2096 to 1f4a6f2 Compare August 25, 2021 03:48
@AAfghahi AAfghahi force-pushed the ch20999_creationMethodValidation branch from 1f4a6f2 to 148c09c Compare August 26, 2021 16:24
@betodealmeida betodealmeida merged commit c66f278 into apache:master Sep 8, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* backend creation method validation

* added tests

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update tests/integration_tests/reports/api_tests.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update tests/integration_tests/reports/api_tests.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/commands/create.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/commands/exceptions.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* revisions

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
* backend creation method validation

* added tests

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update tests/integration_tests/reports/api_tests.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update tests/integration_tests/reports/api_tests.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/dao.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/commands/create.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* Update superset/reports/commands/exceptions.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

* revisions

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.0 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 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants