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(permalink): migrate to marshmallow codec #24166

Merged
merged 2 commits into from
May 22, 2023

Conversation

villebro
Copy link
Member

@villebro villebro commented May 22, 2023

SUMMARY

A recent PR #23888 that migrated serialization of permalink entries from Pickle to JSON caused a regression when decoding permalinks containing URL params. More specifically, this happened due to the fact that we were encoding the value with a JSON codec, which doesn't distinguish between tuples and lists. As the urlParams property in the permalink state was of the format Optional[List[Tuple[str, str]]], they became Optional[List[List[str]]] after deserialization, which urllib.parse.urlencode is unable to process.

To get around this we introduce a new codec called MarshmallowKeyValueCodec. This extends the JsonKeyValueCodec but takes a Marshmallow Schema in the constructor, and uses that during encoding/decoding. This ensures that an entry that has been serialized in JSON format can contain tuples after decoding.

Thanks @Always-prog for raising this issue in #24160.

AFTER

Now permalinks containing urlParams work as expected:
image

BEFORE

Previously permalinks with URL params would throw a 500:

{
  "errors": [
    {
      "message": "not a valid non-string sequence or mapping object", 
      "error_type": "GENERIC_BACKEND_ERROR", 
      "level": "error",
      "extra": {
        "issue_codes": [
          {
            "code": 1011, 
            "message": "Issue 1011 - Superset encountered an unexpected error."
           }
        ]
      }
    }
  ]
}

TESTING INSTRUCTIONS

  1. Create a Dashboard or Explore permalink containing a URL param abc=123
  2. Navigate to the permalink and notice the error

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

{
"dashboardId": "1",
"state": {
"urlParams": [("foo", "bar"), ("foo", "baz")],
Copy link
Member Author

Choose a reason for hiding this comment

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

Notice how the decoded value now contains tuples which aren't natively supported by JSON.

@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Merging #24166 (7e41ecd) into master (1583090) will decrease coverage by 0.01%.
The diff coverage is 70.58%.

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

@@            Coverage Diff             @@
##           master   #24166      +/-   ##
==========================================
- Coverage   68.27%   68.26%   -0.01%     
==========================================
  Files        1952     1955       +3     
  Lines       75367    75451      +84     
  Branches     8208     8215       +7     
==========================================
+ Hits        51455    51510      +55     
- Misses      21806    21835      +29     
  Partials     2106     2106              
Flag Coverage Δ
hive 53.31% <64.78%> (+<0.01%) ⬆️
mysql 78.95% <84.50%> (+<0.01%) ⬆️
postgres 79.02% <84.50%> (+<0.01%) ⬆️
presto 53.24% <64.78%> (+<0.01%) ⬆️
python 82.82% <87.32%> (+<0.01%) ⬆️
sqlite 77.55% <84.50%> (+<0.01%) ⬆️
unit 53.32% <84.50%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
...i-core/src/color/colorSchemes/sequential/common.ts 100.00% <ø> (ø)
...plugins/legacy-preset-chart-deckgl/src/factory.tsx 0.00% <ø> (ø)
...preset-chart-deckgl/src/layers/Heatmap/Heatmap.tsx 0.00% <0.00%> (ø)
...d/plugins/legacy-preset-chart-deckgl/src/preset.js 100.00% <ø> (ø)
...-frontend/src/features/alerts/AlertReportModal.tsx 54.44% <0.00%> (ø)
...cy-preset-chart-deckgl/src/layers/Heatmap/index.ts 66.66% <66.66%> (ø)
superset/dashboards/permalink/commands/create.py 90.32% <66.66%> (-2.54%) ⬇️
superset/explore/permalink/commands/create.py 88.88% <66.66%> (-2.03%) ⬇️
superset/viz.py 61.39% <66.66%> (+0.02%) ⬆️
...et-chart-deckgl/src/layers/Heatmap/controlPanel.ts 83.33% <83.33%> (ø)
... and 11 more

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

@villebro villebro force-pushed the villebro/marshmallow-permalink branch from d60b2b2 to dd9720b Compare May 22, 2023 08:19
@villebro villebro merged commit 71d0543 into apache:master May 22, 2023
@villebro villebro added the 2.1.1 label May 22, 2023
@villebro villebro deleted the villebro/marshmallow-permalink branch May 23, 2023 06:04
@eschutho eschutho added the v2.1 label Jul 11, 2023
eschutho pushed a commit that referenced this pull request Jul 11, 2023
@mistercrunch mistercrunch added 🍒 2.1.1 🍒 2.1.2 🍒 2.1.3 🏷️ 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 🍒 2.1.1 🍒 2.1.2 🍒 2.1.3 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants