-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
fix: Ch31968query context #17600
Conversation
7c72eb9
to
409c74b
Compare
superset/charts/commands/export.py
Outdated
@@ -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"): |
There was a problem hiding this comment.
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"]: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"]
42c4714
to
60d09c6
Compare
d250bbf
to
d712364
Compare
There was a problem hiding this 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.
d712364
to
6fa51cd
Compare
try: | ||
query_context = slc.get_query_context() | ||
except DatasetNotFoundError: | ||
query_context = None |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) == { |
There was a problem hiding this comment.
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.
* a lot of console logs * import and export of query context (cherry picked from commit d7e3a60)
🏷️ 2021.46 |
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