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: Ch31968query context #17600

Merged
merged 5 commits into from
Dec 1, 2021
Merged

Conversation

AAfghahi
Copy link
Member

@AAfghahi AAfghahi commented Nov 30, 2021

SUMMARY

The were some recent changes that are causing an error when reading a query context that has a dataset id tied to a dataset that does not exist. In the case where we found this error, the invalid dataset id was caused by exporting query_context which was then exporting the dataset id instead of a uuid or something that could be transferred from one superset instance to another. So this PR removes the query_context from export and import and also does not throw an error if a chart tries to read the query_context and hits a dataset not found error.

In the near future, we should think about cleaning up any existing query contexts in a migration or script that point to a dataset that does not exist.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

n/a

TESTING INSTRUCTIONS

export a dashboard with charts that have query_context and import them. When loading the dashboard in the new instance, there should be no errors.

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 ch31968queryContext branch 2 times, most recently from 7c72eb9 to 409c74b Compare November 30, 2021 20:23
@@ -63,6 +63,9 @@ def _export(model: Slice) -> Iterator[Tuple[str, str]]:
except json.decoder.JSONDecodeError:
logger.info("Unable to decode `params` field: %s", payload["params"])

if payload.get("query_context"):
Copy link
Member

Choose a reason for hiding this comment

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

payload = {
  key: value
  for key, value in payload.items()
  if key not in REMOVE_KEYS
}

@@ -96,10 +96,5 @@ def _import(
}
)
config["params"].update({"datasource": dataset.uid})
if config["query_context"]:
Copy link
Member

Choose a reason for hiding this comment

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

We need to delete query_context if it exists:

# fix old exports before PR
if config["query_context"]:
    config["query_context"] = None

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be better if this was

if config["query_context"]:
   del config["query_context"]

@AAfghahi AAfghahi force-pushed the ch31968queryContext branch 2 times, most recently from 42c4714 to 60d09c6 Compare November 30, 2021 22:19
@AAfghahi AAfghahi marked this pull request as ready for review November 30, 2021 22:20
@AAfghahi AAfghahi force-pushed the ch31968queryContext branch 5 times, most recently from d250bbf to d712364 Compare December 1, 2021 00:08
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

LGTM but could also use a review from @betodealmeida who has more context on this part of the codebase.

try:
query_context = slc.get_query_context()
except DatasetNotFoundError:
query_context = None
Copy link
Member

@eschutho eschutho Dec 1, 2021

Choose a reason for hiding this comment

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

@AAfghahi and I also talked about maybe writing a script/migration as a follow up that will remove any existing query_context fields from charts if they contain an invalid dataset id. Either way, it seems that if query context is failing in any way here, that it would be just as fine not to use it.

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 good!

It would be nice to add unit testing checking that (1) exports don't have query_context and (2) imports work with and without query_context.

@@ -191,34 +190,6 @@ def test_import_v1_chart(self, mock_g):
)
assert dataset.table_name == "imported_dataset"
assert chart.table == dataset
assert json.loads(chart.query_context) == {
Copy link
Member

Choose a reason for hiding this comment

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

also @AAfghahi is going to fast-follow with a test for these changes.

@eschutho eschutho merged commit d7e3a60 into apache:master Dec 1, 2021
@eschutho eschutho deleted the ch31968queryContext branch December 1, 2021 00:51
sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Dec 1, 2021
* a lot of console logs

* import and export of query context

(cherry picked from commit d7e3a60)
@sadpandajoe
Copy link
Member

🏷️ 2021.46

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

Successfully merging this pull request may close these issues.

5 participants