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(dashboard-export): Fixes datasetId is not replaced with datasetUuid in Dashboard export in 4.1.x #30425

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

fmannhardt
Copy link
Contributor

SUMMARY

Fixes #30424 by duplicating the code that rewrites the native_filter_configuration to use datasetUuid instead of datasetId into the _file_content method of ExportDashboardsCommand.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before the targets attribute of native_filter_configuration items includes datasetId:

    targets:
    - datasetId: 17
      column:
        name: column_name

After it just has datasetUuid:

    targets:
    - column:
        name: column_name
      datasetUuid: 7ac464dc-315a-4c9e-b9ec-048d7bbcf382```

TESTING INSTRUCTIONS

(1) Create a dashboard with any chart
(2) Add a single value filter for any column
(3) Export the dashboard
(4) Verify that datasetUuid is used to refer to the dataset and not datasetId

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

@dosubot dosubot bot added the dashboard:export Related to exporting dashboards label Sep 28, 2024
Copy link

codecov bot commented Sep 28, 2024

Codecov Report

Attention: Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.92%. Comparing base (76d897e) to head (cedca0b).
Report is 841 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/dashboard/export.py 14.28% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #30425       +/-   ##
===========================================
+ Coverage   60.48%   83.92%   +23.43%     
===========================================
  Files        1931      533     -1398     
  Lines       76236    38546    -37690     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    32348    -13766     
+ Misses      28017     6198    -21819     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 48.99% <0.00%> (-0.17%) ⬇️
javascript ?
mysql 76.76% <14.28%> (?)
postgres 76.88% <14.28%> (?)
presto 53.48% <0.00%> (-0.32%) ⬇️
python 83.92% <14.28%> (+20.43%) ⬆️
sqlite 76.33% <14.28%> (?)
unit 60.71% <0.00%> (+3.08%) ⬆️

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.

@mistercrunch
Copy link
Member

Could you write a unit test that would fail before and succeed after? That will help review the logic by stating the assumptions in a unit test.

@fmannhardt
Copy link
Contributor Author

fmannhardt commented Sep 28, 2024

Happy to do so. Since I have no clue of the testing approach of Superset, could you help me find the correct spot to test? Would the correct file be:

ExportDashboardsCommand.return_value.run.return_value = [

or rather an integration test (since this also concerns code that also exports other resources:
class TestExportDashboardsCommand(SupersetTestCase):

@fmannhardt
Copy link
Contributor Author

After some more searching, the example data used in the tests comes from here:
https://github.com/apache/superset/blob/master/superset/examples/world_bank.py
and are manually created via code right? Or is there somewhere examples that exists as YAML files using the import/export feature?

Searching for native in the examples folder does not find anything:
https://github.com/search?q=repo%3Aapache%2Fsuperset+path%3A%2F%5Esuperset%5C%2Fexamples%5C%2F%2F+native&type=code

So, I would need to write code to create a dashboard with native filters from scratch? Or would there be a simpler way to write such test? I would need some guidance.

@sadpandajoe
Copy link
Member

@fmannhardt I created a PR to the covid vaccine example dashboard. I'm guessing you can probably add a test here: https://github.com/apache/superset/blob/master/tests/integration_tests/dashboards/commands_tests.py#L67 or update one of the tests to make sure when exporting native filter meta data is there.

@Vitor-Avila
Copy link
Contributor

Hey @fmannhardt,

Thanks for working on this fix! 🙏

Looking at the code changes, I noticed you have re-introduced that code block to file_content, but it also remains present in the _export method. Is it required to have this block in both? For instance I see the dataset_id = target.pop("datasetId", None) in both blocks.

If we need them in both places, should we consider to move this logic to a helper/etc method to make it DRYer?

@sadpandajoe sadpandajoe added the v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch label Oct 3, 2024
@fmannhardt
Copy link
Contributor Author

@Vitor-Avila I think it is required in both places to also invoke the export of the related datasets via yield from ExportDatasetsCommand([dataset_id]).run(). I agree that a refactoring would make sense. However, then there are also other parts that are duplicated such as:

        payload = model.export_to_dict(
            recursive=False,
            include_parent_ref=False,
            include_defaults=True,
            export_uuids=True,

It seems to me that a completely different approach to separate the export to YAML/JSON and walking the dependency graph of the to be exported dashboard would be better. Maybe, first collecting all the dependencies and then going through the list of dependencies and exporting them. However, that would exceed the capacity that I have for contributing right now (and I am also not aware of any design decision that led to the current approach).

I will try to add the test in the next few days.

@sadpandajoe
Copy link
Member

@fmannhardt @Vitor-Avila as this would be a regression for 4.1, let's I'd advise that we just add the tests and then if we need to refactor, refactor in a separate pr.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 5, 2024
@fmannhardt
Copy link
Contributor Author

It seems that I also need to write a fixture for the COVID dashboard, right? Bare with me, still exploring the setup of Superset testing and locally many other tests fail probably due to missing dependencies. I will try to look at this tomorrow.

@villebro
Copy link
Member

villebro commented Oct 7, 2024

@fmannhardt thanks for working on this super critical regression. I will be reviewing this today and do my best to help unblock you.

@villebro
Copy link
Member

villebro commented Oct 7, 2024

Note: this is a fix for a regression that was introduced by #26765

@villebro
Copy link
Member

villebro commented Oct 7, 2024

It seems that I also need to write a fixture for the COVID dashboard, right? Bare with me, still exploring the setup of Superset testing and locally many other tests fail probably due to missing dependencies. I will try to look at this tomorrow.

@fmannhardt you are correct - if there isn't a fixture that creates this dashboard + related assets, then you will need to add one. Let me know if you need help with this.

@fmannhardt
Copy link
Contributor Author

fmannhardt commented Oct 7, 2024

Happy to help and thanks for the work on Superset. I may have time to look at this tomorrow (UTC+1). So, the existing fixtures hard code the dashboard and do not load from the examples? Just so I understand how to write it. It would be a copy of world_bank_dashboard.py but then the COVID dashboard code in there?

In case, it is easy for you to add the fixture I am also happy to update the test I wrote to work against it.

@villebro
Copy link
Member

villebro commented Oct 7, 2024

Happy to help and thanks for the work on Superset. I may have time to look at this tomorrow (UTC+1). So, the existing fixtures hard code the dashboard and do not load from the examples? Just so I understand how to write it. It would be a copy of world_bank_dashboard.py but then the COVID dashboard code in there?

In case, it is easy for you to add the fixture I am also happy to update the test I wrote to work against it.

@fmannhardt let me take a look how it's been implemented (my memory is rusty on these particular fixtures)..

@villebro
Copy link
Member

villebro commented Oct 7, 2024

@fmannhardt I took a quick look at that particular fixture, and it seems to be mostly reusing existing logic. However, the data seems to be randomly generated for some reason. I'm not sure why, but maybe it's to avoid unnecessary web traffic. Please keep an open mind while working on the fixture, and if you feel some aspect could be improved compared to the World Bank fixture, then please by all means feel free to implement accordingly. I'm in UTC-0700, so I can help/review tomorrow morning my time if needed, likely after you've had a chance to take a stab at it first.

@fmannhardt
Copy link
Contributor Author

@villebro I took another look but this would take me much more time to understand. I don't even need to data for the test. Only the have the COVID dashboard and its dataset loaded and available to be queries by UUID f4065089-110a-41fa-8dd7-9ce98a65e250. It is probably trivial but would take me several hours. So, it would take some more days. Please feel free to add this.

@villebro
Copy link
Member

villebro commented Oct 8, 2024

@fmannhardt I totally understand. Feel free to disable the added test - I'll open a PR that adds the necessary fixtures and re-enables the test.

@fmannhardt
Copy link
Contributor Author

Test is disabled and current master branch is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:export Related to exporting dashboards size/M v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dashboard export does not export datasetUuid in native filter targets but datasetId in 4.1
5 participants