Skip to content

Conversation

@yong1le
Copy link
Contributor

@yong1le yong1le commented Oct 30, 2025

SUMMARY

This PR fixes a bug where cross filtering on a world map chart always uses the cca3 country code format, even if other codes (cca2, cioc) were selected as the countryFieldType during chart creation.

superset/viz.py

The backend currently provides country results to the frontend in the format:

{
    "country": "string",
    "name": "string",
    // … other fields  
}

The country field is the cca3 code of the country, and name is the country’s full name. country must be sent as a cca3 code, because the frontend plugin used for maps only recognizes cca3 country codes. To improve interoperability and make additional code formats (e.g., cca2, cioc) available without altering the existing response structure, we introduce an additional object field code:

{
    "country": "string",
    "name": "string",
    "code": "string"
    // … other fields  
}

This approach was chosen because it preserves backward compatibility with existing frontend expectations (country remains cca3). The code field is retrieved from the country module like all the other country data, and it uses form_data["country_fieldtype"] to know which field type the user requested.

superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js

This frontend component handles the world map chart and manages cross-filter interactions through the getCrossFilterDataMask function, which is triggered when a user clicks on a country. Previously, getCrossFilterDataMask only checked if countryFieldType == "name".

If countryFieldType == "name", it used the backend name field (e.g., "Canada"). Otherwise, it used the country field, which was always in cca3 format (e.g., "CAN"). Now, instead of falling back to country, we fall back to code, which will be in the format the user selected when the chart was created.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

I created a dataset with cca2 country codes, and created 2 charts with it on the same dashboard.

Before

When selecting Canada on chart CA2-1, nothing is shown on chart CA2-2, even though it also has Canada in the dataset. You can also see on the left sidebar that CAN is used to filter the charts, even though cca2 is set as the country field type.
image

After

When selecting Canada on chart CA2-1, it is also filtered on chart CA2-2. On the left sidebar, you can also see that CA is used to filter the charts.
image

TESTING INSTRUCTIONS

Steps to Verify:

  1. Create a dataset that includes country identifier fields (e.g., name, cca2).
  2. Create two world map charts using these datasets with the countryFieldType as cca2.
  3. Add both charts to the same dashboard.
  4. Interact with the maps by selecting a country.

Expected Result:

Observe that when you click on a country in one map, the corresponding country is highlighted in all other maps.

ADDITIONAL INFORMATION

  • Has associated issue: Fixes World map chart type changes country code format in dashboard filter #34024
  • 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

@korbit-ai
Copy link

korbit-ai bot commented Oct 30, 2025

Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment /korbit-review.

Your admin can change your review schedule in the Korbit Console

@rusackas
Copy link
Member

rusackas commented Nov 3, 2025

Heads up to @villebro since we're touching his arch-nemesis file, viz.py

@yong1le yong1le marked this pull request as ready for review November 3, 2025 23:05
@dosubot dosubot bot added change:backend Requires changing the backend change:frontend Requires changing the frontend viz:charts:map Related to Map charts labels Nov 3, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Performance Duplicated country field resolution logic ▹ view
Functionality Incorrect mapData key lookup for new country field types ▹ view
Design Duplicated Country Resolution Logic ▹ view
Performance Inefficient dictionary creation in loop ▹ view
Functionality Missing key validation for country codes ▹ view
Files scanned
File Path Reviewed
superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js
superset/viz.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.74%. Comparing base (6e27bee) to head (bedc570).
⚠️ Report is 90 commits behind head on master.

Files with missing lines Patch % Lines
superset/viz.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #35919       +/-   ##
===========================================
+ Coverage        0   68.74%   +68.74%     
===========================================
  Files           0      622      +622     
  Lines           0    45718    +45718     
  Branches        0     4975     +4975     
===========================================
+ Hits            0    31428    +31428     
- Misses          0    13045    +13045     
- Partials        0     1245     +1245     
Flag Coverage Δ
hive 44.20% <0.00%> (?)
mysql 67.82% <0.00%> (?)
postgres 67.87% <0.00%> (?)
presto 47.76% <0.00%> (?)
python 68.71% <0.00%> (?)
sqlite 67.48% <0.00%> (?)
unit 100.00% <ø> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yong1le yong1le changed the title Bug/world map chart changes country code format in crossfilter fix(dashboard): Ensure world map chart uses correct country code format in crossfilter Nov 6, 2025
@yong1le yong1le changed the title fix(dashboard): Ensure world map chart uses correct country code format in crossfilter fix(dashboard): ensure world map chart uses correct country code format in crossfilter Nov 6, 2025
@pull-request-size pull-request-size bot added size/XS and removed size/M labels Nov 6, 2025
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.

LGTM, thanks for the fix!

@villebro villebro merged commit fb8eb2a into apache:master Nov 17, 2025
85 of 87 checks passed
@sadpandajoe sadpandajoe added the v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch label Nov 17, 2025
sadpandajoe pushed a commit that referenced this pull request Nov 17, 2025
kshi020302 pushed a commit to jl141/superset that referenced this pull request Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend change:frontend Requires changing the frontend plugins size/XS v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch viz:charts:map Related to Map charts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

World map chart type changes country code format in dashboard filter

4 participants