Skip to content

fix: do not drop falsy shard keys in convert_points_update_operation - #1279

Merged
joein merged 1 commit into
qdrant:devfrom
ErenAta16:fix-update-operation-falsy-shard-key
Jul 23, 2026
Merged

joein merged 1 commit into
qdrant:devfrom
ErenAta16:fix-update-operation-falsy-shard-key

Conversation

@ErenAta16

Copy link
Copy Markdown
Contributor

What's broken

All eight branches of RestToGrpc.convert_points_update_operation gate the shard key on truthiness:

shard_key_selector = (
    cls.convert_shard_key_selector(model.upsert.shard_key)
    if model.upsert.shard_key
    else None
)

ShardKey = Union[StrictInt, StrictStr], so 0 and "" are valid shard keys that evaluate to False. They are silently replaced with None, and the operation gets routed by the default rules instead of to the requested shard. Nothing raises, so the write just lands somewhere else.

Repro against dev, converting each operation type with shard_key=0:

shard_key = 0

LOST UpsertOperation            shard_key_selector present=False keys=[]
LOST DeleteOperation            shard_key_selector present=False keys=[]
LOST SetPayloadOperation        shard_key_selector present=False keys=[]
LOST OverwritePayloadOperation  shard_key_selector present=False keys=[]
LOST DeletePayloadOperation     shard_key_selector present=False keys=[]
LOST ClearPayloadOperation      shard_key_selector present=False keys=[]
LOST UpdateVectorsOperation     shard_key_selector present=False keys=[]
LOST DeleteVectorsOperation     shard_key_selector present=False keys=[]

8/8 operations silently dropped the shard key
control, shard_key=1 -> [number: 1]

With this patch:

OK   UpsertOperation            shard_key_selector present=True keys=[number: 0]
OK   DeleteOperation            shard_key_selector present=True keys=[number: 0]
OK   SetPayloadOperation        shard_key_selector present=True keys=[number: 0]
OK   OverwritePayloadOperation  shard_key_selector present=True keys=[number: 0]
OK   DeletePayloadOperation     shard_key_selector present=True keys=[number: 0]
OK   ClearPayloadOperation      shard_key_selector present=True keys=[number: 0]
OK   UpdateVectorsOperation     shard_key_selector present=True keys=[number: 0]
OK   DeleteVectorsOperation     shard_key_selector present=True keys=[number: 0]

0/8 operations silently dropped the shard key

Why it matters

This is on the write path. QdrantRemote.batch_update_points (and the async variant) call RestToGrpc.convert_update_operation for every operation when the client is constructed with prefer_grpc=True. A custom-sharded collection keyed on integers loses shard 0 on every batch update, and there is no signal that it happened.

The fix

Switch the eight guards to is not None. The field is declared Optional[ShardKeySelector] with a None default, so None is the only value that should mean "not set". This is the idiom the rest of the file already uses, for example in convert_query_request:

shard_key_selector=(
    cls.convert_shard_key_selector(model.shard_key)
    if model.shard_key is not None
    else None
),

so this only brings the update path in line with the read path. No behaviour changes for None or for any truthy key.

Testing

test_convert_points_update_operation_falsy_shard_key builds each of the eight REST operation types with shard_key=0 and shard_key="", converts to gRPC, and asserts the selector survives and round-trips back to the original value.

$ pytest tests/conversions/test_validate_conversions.py -q
......................                                                   [100%]
22 passed in 1.16s

Reverting only the conversion.py hunk makes the new test fail on the first operation and leaves the other 21 tests passing, so nothing else in the file depended on the old behaviour. ruff format --line-length=99 reports no changes.

All eight branches of `RestToGrpc.convert_points_update_operation` gate the
shard key on truthiness:

    shard_key_selector = (
        cls.convert_shard_key_selector(model.upsert.shard_key)
        if model.upsert.shard_key
        else None
    )

`ShardKey` is `Union[StrictInt, StrictStr]`, so `0` and `""` are valid keys
that evaluate to False. They get silently replaced with `None`, and the
operation is routed by the default hashing rules instead of to the requested
shard. No error is raised on either side, so the write just lands somewhere
else.

Before, converting each operation type with `shard_key=0`:

    LOST UpsertOperation            shard_key_selector present=False
    LOST DeleteOperation            shard_key_selector present=False
    LOST SetPayloadOperation        shard_key_selector present=False
    LOST OverwritePayloadOperation  shard_key_selector present=False
    LOST DeletePayloadOperation     shard_key_selector present=False
    LOST ClearPayloadOperation      shard_key_selector present=False
    LOST UpdateVectorsOperation     shard_key_selector present=False
    LOST DeleteVectorsOperation     shard_key_selector present=False

    8/8 operations silently dropped the shard key
    control, shard_key=1 -> [number: 1]

After:

    OK   UpsertOperation            shard_key_selector present=True keys=[number: 0]
    ... (all eight)
    0/8 operations silently dropped the shard key

This is on the write path: `QdrantRemote.batch_update_points` calls
`RestToGrpc.convert_update_operation` for every operation when the client is
built with `prefer_grpc=True`, so a custom-sharded collection keyed on
integers loses shard 0 on every batch update.

The same conversion elsewhere in the file already uses the `is not None`
form, for example `convert_query_request`:

    shard_key_selector=(
        cls.convert_shard_key_selector(model.shard_key)
        if model.shard_key is not None
        else None
    ),

so this just brings the update path in line with it. The field is
`Optional[ShardKeySelector]` with a `None` default, and `None` is the only
value that should mean "not set".

Tested with `pytest tests/conversions/test_validate_conversions.py`
(22 passed). The new test fails on all eight operations without the
conversion.py change.
@netlify

netlify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit 19e0f76
🔍 Latest deploy log https://app.netlify.com/projects/poetic-froyo-8baba7/deploys/6a613c93852b2100072490c7
😎 Deploy Preview https://deploy-preview-1279--poetic-froyo-8baba7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b70173a7-59ba-406f-a687-2b716aae863b

📥 Commits

Reviewing files that changed from the base of the PR and between f326784 and 19e0f76.

📒 Files selected for processing (2)
  • qdrant_client/conversions/conversion.py
  • tests/conversions/test_validate_conversions.py

📝 Walkthrough

Walkthrough

Updated point update conversion to check whether shard_key is present rather than truthy across upsert, delete, payload, clear-payload, and vector operations. Added coverage confirming that 0 and "" are converted into shard-key selectors and round-trip back unchanged.

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

Suggested reviewers: joein

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the fix for preserving falsy shard keys in point-update conversion.
Description check ✅ Passed The description matches the code changes and test additions, and clearly explains the shard-key bug and fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@joein

joein commented Jul 23, 2026

Copy link
Copy Markdown
Member

Hey @ErenAta16

Thanks for pointing it out!

I'll review the PR

@joein

joein commented Jul 23, 2026

Copy link
Copy Markdown
Member

looks good to me!

let's wait for the green ci

@joein
joein self-requested a review July 23, 2026 16:19
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.

2 participants