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

Keep result-metadata of native queries if possible #39184

Merged
merged 2 commits into from Feb 27, 2024

Conversation

metamben
Copy link
Contributor

@metamben metamben commented Feb 26, 2024

Part of #37009.

Related FE PR: #39201

The problem this PR is fixing is that for native queries the before update hook of the card doesn't populate result_metadata, but sets it to nil instead (to make sure we have no stale metadata, which we consider worse than no metadata at all). When a native question is updated and the result metadata doesn't change, the t2/changes function omits result_metadata and the above behavior is triggered.

To solve the problem, when a question is updated via the API and we are able to determine the result metadata, we set a flag that forces the use of that metadata (which might mean that the field is left untouched, if there's no change).

This PR doesn't fully solve the problem, because we only set the result metadata if the query finishes in 1.5 s. In other cases, the behavior is unchanged, and the FE will get nil as metadata.

@metamben metamben added the backport Automatically create PR on current release branch on merge label Feb 26, 2024
@metamben metamben self-assigned this Feb 26, 2024
@metabase-bot metabase-bot bot added the .Team/QueryProcessor :hammer_and_wrench: label Feb 26, 2024
:type}
:non-nil #{:dataset_query :display :name :visualization_settings :archived
:enable_embedding :parameters :parameter_mappings :embedding_params
:result_metadata :collection_preview :verified-result-metadata?}))))
Copy link
Contributor Author

@metamben metamben Feb 26, 2024

Choose a reason for hiding this comment

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

In this hunk, only this line contains interesting an change.

Copy link

replay-io bot commented Feb 26, 2024

Status Complete ↗︎
Commit 34e68e5
Results
⚠️ 2 Flaky
2322 Passed

;; remove all the unchanged keys from the map, except for `:id`, so the functions below can do the right thing since
;; they were written pre-Toucan 2 and don't know about [[t2/changes]]...
;;
;; We have to convert this to a plain map rather than a Toucan 2 instance at this point to work around upstream bug
;; https://github.com/camsaul/toucan2/issues/145 .
(-> (into {:id (:id card)} (t2/changes card))
(-> (into {:id (:id card)} (t2/changes (dissoc card :verified-result-metadata?)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Having to add and then remove this data seems a bit noisy. How about update-meta on the card instead of adding a new key to the card itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit vary of relying on meta being preserved. Just naively putting metadata at the point where I now assoc :verified-result-metadata? is not enough, that metadata doesn't reach the before update hook (i.e., card doesn't have it).

Copy link
Contributor

@kamilmielnik kamilmielnik 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 from FE perspective 👍

I have a PR based on this one coming: #39201

@metamben
Copy link
Contributor Author

Since this is for an escalation, I'm merging this as is, we can revisit using meta to pass in the flag.

@metamben metamben merged commit edf55f5 into master Feb 27, 2024
118 of 138 checks passed
@metamben metamben deleted the 37009-keep-native-question-result-metadata branch February 27, 2024 15:30
Copy link

@metamben Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

github-actions bot pushed a commit that referenced this pull request Feb 27, 2024
metabase-bot bot added a commit that referenced this pull request Feb 27, 2024
…9207)

* Keep result-metadata of native queries if possible (#39184)

Part of #37009.

* qp/query->expected-cols -> qp.preprocess/query->expected-cols

---------

Co-authored-by: metamben <103100869+metamben@users.noreply.github.com>
Co-authored-by: Tamás Benkő <tamas@metabase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge .Team/QueryProcessor :hammer_and_wrench:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants