Skip to content

fix(weaviate): wrap fetch_object_by_id again, and keep the v4 list honest - #4714

Open
iruzen-dono wants to merge 1 commit into
traceloop:mainfrom
iruzen-dono:fix/weaviate-fetch-object-by-id
Open

iruzen-dono wants to merge 1 commit into
traceloop:mainfrom
iruzen-dono:fix/weaviate-fetch-object-by-id

Conversation

@iruzen-dono

@iruzen-dono iruzen-dono commented Nov 18, 2026 •

Copy link
Copy Markdown

The bug

On current weaviate-client releases, fetch_object_by_id produces no span, and nothing says so.

WRAPPED_METHODS_v4 points fetch_object_by_id at weaviate.collections.queries.fetch_object_by_id.query. That module existed in the first 4.x releases and was flattened later in the same major; _instrument resolves each entry defensively (except ModuleNotFoundError: continue, then hasattr), so the miss is a silent skip rather than an error. The package still declares _instruments = ("weaviate-client >= 3.26.0, <5").

Measured

Against weaviate-client 4.24.1, 12 of the 16 entries in WRAPPED_METHODS_v4 resolve. The four that do not:

entry what happened upstream
weaviate.collections.queries.fetch_object_by_id.query module removed; class now one level up
weaviate.gql.filter.GraphQL.do do renamed to build
weaviate.gql.aggregate.AggregateBuilder.do do renamed to build
weaviate.gql.get.GetBuilder.do module removed

On weaviate-client 4.4.0 all sixteen resolve, so the list was correct when it was written and drifted afterwards.

The fix

fetch_object_by_id is the one of the four that is a wrong path rather than an API change: the class now lives at weaviate.collections.queries.fetch_object_by_id, which on 4.4.0 re-exports the identical class object from the .query module, so pointing the entry at the parent is behaviour-preserving for the releases that still have both and restores the span everywhere else.

The three weaviate.gql.*.do entries stay wrapped for the 4.x releases that still ship those methods, but they move into WRAPPED_METHODS_v4_legacy. That leaves WRAPPED_METHODS_v4 meaning this must resolve on the client the package runs on, which is a property a test can assert — the legacy list is the part that is allowed to disappear upstream.

Test

One case per entry of WRAPPED_METHODS_v4, importing the module and checking the method on the named holder. No server, no cassette.

All four runs below are real, against the client each one names:

client patch result
4.24.1 without 4 failed, 9 passed — including _FetchObjectByIDQuery.fetch_object_by_id: "has no fetch_object_by_id on weaviate-client 4.24.1: no span will be emitted"
4.24.1 with 13 passed
4.4.0 with 13 passed (older 4.x untouched)

Behaviourally, also on 4.24.1: _FetchObjectByIDQuery.__dict__["fetch_object_by_id"] is NoneType before instrument(), a FunctionWrapper after it, and a plain function again after uninstrument().

ruff check . passes; this repo's lint target does not run ruff format, so nothing was reformatted.

One thing this does not fix

tests/test_weaviate_instrumentation.py has never run in CI: the test dependency group pins weaviate-client>=3.26,<4, so the whole v4 module short-circuits on pytest.importorskip("weaviate.classes"). That is why this drift could sit unnoticed — the CI client has no weaviate.classes at all.

The new test inherits that skip. Making it run means lifting the pin to <5 and giving the test-packages job a weaviate instance, since the v4 fixtures call weaviate.connect_to_local and there are no cassettes for them. I did not do that here: it changes CI for every package in the repo, and this PR should be reviewable as a two-file fix. Say the word and I will open it as a follow-up.

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with Weaviate v4 clients for object retrieval and GraphQL operations.
    • Added checks to catch unsupported v4 methods during instrumentation tests.

…nest

`weaviate.collections.queries.fetch_object_by_id.query` stopped existing in a
later 4.x, so the entry stopped resolving and `_instrument` skipped it without
saying anything: `fetch_object_by_id` has produced no span on current
weaviate-client releases, while the package declares support for `>=3.26,<5`.

Measured on weaviate-client 4.24.1: 12 of the 16 entries in
`WRAPPED_METHODS_v4` resolve. The class now lives one module up, as
`weaviate.collections.queries.fetch_object_by_id`, which is the same class the
`.query` module re-exported on 4.4.0 (checked: identical object), so the path
change is behaviour-preserving on the 4.x releases that still have both.

The other three failures are `weaviate.gql.*.do`: they resolve on 4.4.0 and the
SDK removed them later in the same major. They stay wrapped for the releases
that still ship them, but they move to `WRAPPED_METHODS_v4_legacy` so that
`WRAPPED_METHODS_v4` means "this has to hold on the client we test against" --
which is what the new test asserts, one case per entry.

Test evidence, all against the real client:

- weaviate-client 4.24.1, without the path fix: 4 failed, among them
  `_FetchObjectByIDQuery.fetch_object_by_id` ("has no fetch_object_by_id on
  weaviate-client 4.24.1: no span will be emitted").
- weaviate-client 4.24.1, with the patch: 13 passed.
- weaviate-client 4.4.0, with the patch: 13 passed, so the older 4.x line is
  untouched.
- Behaviourally, on 4.24.1: `_FetchObjectByIDQuery.__dict__["fetch_object_by_id"]`
  is `NoneType` before `instrument()` and a `FunctionWrapper` after it, and a
  plain function again after `uninstrument()`.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 18:59
@CLAassistant

CLAassistant commented Nov 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Weaviate instrumentation updates configured v4 method paths and list composition. A parameterized test checks that each configured v4 method exists on the installed client.

Changes: Weaviate v4 instrumentation

Layer / File(s) Summary
Update and validate v4 method configuration
packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/__init__.py, packages/opentelemetry-instrumentation-weaviate/tests/test_weaviate_instrumentation.py
The _FetchObjectByIDQuery entry now uses the fetch_object_by_id module path. graphql_raw_query joins the GraphQL do entries in WRAPPED_METHODS_v4_legacy, and WRAPPED_METHODS combines the v3, v4, and legacy-v4 lists. A parameterized test checks that each configured v4 method exists on the installed client.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: tibor-reiss, paolorechia

Merge Risk: Minimal · up to b0f02

This updates the Weaviate v4 method paths so fetch_object_by_id is instrumented again on newer clients, and the GraphQL methods remain wrapped. No material merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the Weaviate instrumentation fix and the re-wrapping of fetch_object_by_id, which matches the main change in the summary and objectives. The second clause, keeping the v4 list accurate…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the Weaviate instrumentation fix and the re-wrapping of fetch_object_by_id, which matches the main change in the summary and objectives. The second clause, keeping the v4 list accurate, refers to moving the removed GraphQL do entries into WRAPPED_METHODS_v4_legacy, which is also part of the changeset. The title is specific and uses the conventional fix(scope) form, though it is slightly long at 73 characters.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e25bc983-05d8-4289-b8ba-346a2594844f
Commits

Reviewing files that changed from the base of the PR and between 864f859 and b0f02ec.

Files selected for processing: 2

  • packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/__init__.py
  • packages/opentelemetry-instrumentation-weaviate/tests/test_weaviate_instrumentation.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants