Repository navigation
Fixes 32030: Look up Query entities by service-qualified FQN - #32031
Conversation
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
| try: | ||
| resp = self.client.put(self.get_suffix(Query), data=query.model_dump_json()) | ||
| if resp and resp.get("id"): | ||
| query_entity = Query(**resp) | ||
| except APIError as err: | ||
| # Concurrent create: look up the FQN we just raced on, then still | ||
| # attach usage/users/usedBy. Do not reuse __get_query_by_hash — it | ||
| # caches misses. | ||
| if err.status_code == 409: | ||
| query_entity = self.get_by_name(entity=Query, fqn=fqn) | ||
| else: | ||
| raise |
There was a problem hiding this comment.
💡 Edge Case: 409 retry only catches APIError, not raw HTTPError
The new retry only handles APIError, but _one_request only wraps HTTP errors in APIError when the response body contains a code field (client.py:391-396); otherwise it re-raises the raw requests HTTPError. A 409 conflict whose body lacks code would therefore escape the except APIError and propagate uncaught, defeating the concurrent-create recovery. OpenMetadata error responses normally include code, so this is unlikely in practice, but consider catching by HTTP status (e.g. inspecting err.response.status_code on HTTPError) or confirming the server always returns a coded 409 body.
Was this helpful? React with 👍 / 👎
There was a problem hiding this comment.
A 409 from this endpoint includes code, so it shows up as APIError — same thing the usage sink already handles. I'd leave the catch as-is unless we hit a good response without that.
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
1 similar comment
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
977624c to
0851e32
Compare
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
…d FQN Usage get-or-create was asking for the bare SQL hash. The server stores queries as service.hash, so a second table with the same SQL 409'd and skipped usage/users/usedBy. Look up the same FQN query-cost already uses, and retry GET after a create race. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
84f8e8e to
3b58f53
Compare
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
@harshach I rebased the PR and it seems GHA removed the |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsUpdates Query entity lookups to use service-qualified FQNs and handles duplicate entity creation errors with GET retries. Consider ensuring that the 409 retry catches raw HTTP errors alongside APIError instances. 💡 Edge Case: 409 retry only catches APIError, not raw HTTPError📄 ingestion/src/metadata/ingestion/ometa/mixins/query_mixin.py:61-72 The new retry only handles 🤖 Prompt for agentsOptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
|
Hey @larspettermadsstuen, thanks for this. Merged main in and fixed one thing that broke on the way: main had dropped |
5197d0a
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
Thank you! |
…pen-metadata#32031) changed Query lookups to key on service.<hash> insteadof the bare hash, since the same SQL under two services must resolve totwo distinct Query entities. The cache here still keyed on the bare hash,so after merging main, identical SQL seen under a second service wouldincorrectly hit the first service's cached entity and attach usage to thewrong service.Key the cache on the same qualified FQN the lookup uses instead. Add aregression test covering two services sharing one SQL statement, and ranruff format/check on the touched files per review feedback.
…pen-metadata#32254) * fix(ingestion): cache Query and User lookups during usage ingestionWrap _get_or_create_query with a SkipNoneLRUCache keyed by query hash sorepeated tables referencing the same SQL skip the redundant GET/PUT, whilenever caching a miss (another table may have just created the Query).Add get_cached_user_reference, backed by an LRUCache keyed by username,shared between the staging get_by_name(User) call and the lifecycleget_entity_reference(User) call, caching misses too since a user absentat the start of a run will not appear mid-run.Fixes open-metadata#32210 * fix: address review feedback- Restore .root when extracting FQN from cached User EntityReference in staging, fixing a bug where a model object was passed to CreateQueryRequest(users=...) instead of a string.- Scope Query and User reference caches per-OpenMetadata-client-instance instead of at the class level, so multiple clients/catalogs in the same process never share cached data.- Reduce cache sizes from 4096 to 1000 to match repo convention. * fix(ingestion): resolve usage cache review feedback Cover failed query lookup and creation retries, and align the cache changes with current Python formatting. * fix(ingestion): handle cached user references * fix: key Query cache on service-qualified FQN, not bare hashUpstream (open-metadata#32031) changed Query lookups to key on service.<hash> insteadof the bare hash, since the same SQL under two services must resolve totwo distinct Query entities. The cache here still keyed on the bare hash,so after merging main, identical SQL seen under a second service wouldincorrectly hit the first service's cached entity and attach usage to thewrong service.Key the cache on the same qualified FQN the lookup uses instead. Add aregression test covering two services sharing one SQL statement, and ranruff format/check on the touched files per review feedback. * fix: apply ruff formatting (trailing whitespace, EOF newline) --------- Co-authored-by: Pablo Takara <[email protected]> Co-authored-by: IceS2 <[email protected]> Co-authored-by: Shailesh Parmar <[email protected]>



Describe your changes:
Fixes #32030
Usage ingestion looked up Query entities by the MD5 of the SQL only. The server stores them as
service.hash, so a second table with the same query hit 409 and the usage sink skipped attaching usage / users / usedBy.This looks up
service.hashthe same way query-cost already does. If create still 409s (two tables racing), we GET again and keep writing the relations.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
service.hash) and still PUTs/usageservice.hashand both have usageUnit tests
ingestion/tests/unit/ometa/test_query_mixin.pyquery_mixin.pyoverall (get_entity_queries/publish_query_costunchanged and not exercised here). Changed get-or-create / FQN lookup paths are covered.query_mixin.py(5 tests, all passing locally)Backend integration tests
Ingestion integration tests
ingestion/tests/integration/ometa/test_ometa_table_api.py(test_same_query_on_second_table_attaches_usage)Playwright (UI) tests
Manual testing performed
pytest ingestion/tests/unit/ometa/test_query_mixin.py(5 passed)openmetadata/db:2.0.0+openmetadata/server:2.0.0(skip Maven; no JDK).GET /api/v1/system/version→2.0.0pytest tests/integration/ometa/test_ometa_table_api.py::TestOMetaTableAPI::test_same_query_on_second_table_attaches_usage(1 passed)UI screen recording / screenshots:
Not applicable.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
For UI changes: I attached a screen recording and/or screenshots above.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
Greptile Summary
The PR updates ingestion to look up Query entities by their service-qualified FQN and retries that lookup after a create conflict.
service.hashQuery FQN.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Reviews (6): Last reviewed commit: "Merge branch 'main' into fix-query-fqn-l..." | Re-trigger Greptile