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

Preserve FK key metadata on native models #42866

Merged
merged 2 commits into from
May 20, 2024

Conversation

metamben
Copy link
Contributor

@metamben metamben commented May 17, 2024

Fixes #42130.

This PR assumes that the only way a native model can have columns with FK semantic types is if a user specified it by editing the metadata.

TODO

  • unit test

Fixes #42130.

This PR assumes that the only way a native model can have columns with FK semantic types is if a user specified it by
editing the metadata.
@metabase-bot metabase-bot bot added the .Team/QueryProcessor :hammer_and_wrench: label May 17, 2024
@metamben metamben marked this pull request as ready for review May 17, 2024 23:16
@metamben metamben requested a review from camsaul as a code owner May 17, 2024 23:16
Copy link

replay-io bot commented May 17, 2024

Status Complete ↗︎
Commit 61cc6af
Results
⚠️ 8 Flaky
2511 Passed

db (t2/select-one Database :id database_id)
;; a native model can have columns with keys as semantic types on if a user specified it
trust-semantic-keys? (and (= (:type card) :model)
(= (-> card :dataset_query :type) :native))]
Copy link
Contributor

Choose a reason for hiding this comment

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

A regular (mbql) model can also have metadata overrides with FKs for columns that are not FKs in the DB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ranquild Do you have an example when that information gets lost? (The FK override on mbql models worked for me.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have an example. I think you're right and that's the fix we need to do. It should be safe to "trust" FK metadata on native queries because it won't be set automatically.

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've just noticed the typo in the comment. I meant "only if a user specified it", not "on if a user specified it".

@ranquild ranquild merged commit 1935b08 into metrics-v2 May 20, 2024
115 of 162 checks passed
@ranquild ranquild deleted the 42130-preserve-fk-keys-on-native-models branch May 20, 2024 12:25
@ranquild ranquild added backport Automatically create PR on current release branch on merge and removed backport Automatically create PR on current release branch on merge labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.Team/QueryProcessor :hammer_and_wrench:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants