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(annotations): handle required fields properly #17234

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented Oct 26, 2021

SUMMARY

Currently it's possible to create annotations and annotation layers via the API that cause the frontend to crash. For instance, by defining an annotation layer with a null name, the edit window crashes with the following error:

image

Also, editing a previously created annotation where the json_metadata field had been unset (null), trying to save the annotation resulted in the following error:

image

This PR updates both the annotation layer and annotation marshmallow schemas to require the minimum amount of defined or non-null values. Note that when leaving out a property on a PUT request, the original object leaves the omitted values untouched, hence a very permissive schema for PUT operations (no required fields). In addition, the frontend logic is updated to no longer crash if an object that was created prior to this PR is edited.

Test cases are added to all relevant permutations of allowed and incorrect POST/PUT payloads. Affected API tests are also updated to correspond to the new minimum requirements.

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

@codecov
Copy link

codecov bot commented Oct 26, 2021

Codecov Report

Merging #17234 (7e34a51) into master (ef01cbb) will decrease coverage by 0.07%.
The diff coverage is 92.85%.

❗ Current head 7e34a51 differs from pull request most recent head 8feedc1. Consider uploading reports for the commit 8feedc1 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17234      +/-   ##
==========================================
- Coverage   76.82%   76.75%   -0.08%     
==========================================
  Files        1038     1037       -1     
  Lines       55597    55609      +12     
  Branches     7585     7588       +3     
==========================================
- Hits        42715    42680      -35     
- Misses      12632    12679      +47     
  Partials      250      250              
Flag Coverage Δ
mysql 81.95% <100.00%> (+0.01%) ⬆️
postgres 81.96% <100.00%> (+0.01%) ⬆️
presto ?
python 82.04% <100.00%> (-0.16%) ⬇️
sqlite 81.63% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
superset-frontend/src/components/Select/Select.tsx 92.35% <ø> (ø)
...d/components/DashboardBuilder/DashboardBuilder.tsx 90.17% <ø> (ø)
...tend/src/explore/components/ExploreChartHeader.jsx 6.84% <0.00%> (-0.20%) ⬇️
...ontend/src/filters/components/Select/buildQuery.ts 100.00% <ø> (ø)
superset-frontend/src/setup/setupColors.ts 100.00% <ø> (ø)
superset/annotation_layers/schemas.py 100.00% <ø> (ø)
...et-frontend/src/dashboard/components/Dashboard.jsx 81.88% <100.00%> (+3.79%) ⬆️
...ponents/filterscope/renderFilterScopeTreeNodes.jsx 87.50% <100.00%> (+0.83%) ⬆️
...tend/src/views/CRUD/annotation/AnnotationModal.tsx 60.44% <100.00%> (ø)
...ews/CRUD/annotationlayers/AnnotationLayerModal.tsx 69.47% <100.00%> (ø)
... and 7 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 ef01cbb...8feedc1. Read the comment docs.

@geido geido closed this Oct 26, 2021
@geido geido reopened this Oct 26, 2021
@villebro villebro requested a review from geido October 26, 2021 16:46
Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +61 to +62
required=True,
allow_none=False,
Copy link
Member Author

Choose a reason for hiding this comment

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

required=True only makes sure the property is defined, so here we need to also add allow_none=False to make sure null values aren't accepted.

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for the comprehensive unit test.

@villebro villebro merged commit 4316fe6 into apache:master Oct 27, 2021
@villebro villebro deleted the villebro/annotation-null branch October 27, 2021 05:42
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.

Thank you for fixing this!

@@ -0,0 +1,157 @@
# Licensed to the Apache Software Foundation (ASF) under one
Copy link
Member

Choose a reason for hiding this comment

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

Should we place these on tests/unit_tests/annotation_layers instead? they seem more like unit tests then integration tests. It would be nice also to place a test on the API integration tests that would fail on current master but succeed on this PR

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 comment @dpgaspar - you're absolutely right, these should have been placed on the unit tests (completely forgot about the new split). We'll do that + add an IT in a follow up shortly 👍

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.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 preset-io size/L 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants