Skip to content

Comments

[cp2.6]fix:remove db_name from grpchandler to client (#3211)#3226

Merged
sre-ci-robot merged 3 commits intomilvus-io:2.6from
jac0626:cp_dbname_2.6
Jan 23, 2026
Merged

[cp2.6]fix:remove db_name from grpchandler to client (#3211)#3226
sre-ci-robot merged 3 commits intomilvus-io:2.6from
jac0626:cp_dbname_2.6

Conversation

@jac0626
Copy link
Collaborator

@jac0626 jac0626 commented Jan 23, 2026

see #3175

Cherry-picked from 8e0daa0, excluding snapshot-related changes from 262ab27.

Signed-off-by: silas.jiang <[email protected]>
@gemini-code-assist
Copy link

Summary of Changes

Hello @jac0626, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant architectural change in how database context is managed within the PyMilvus client library. By shifting db_name management from the connection level to a per-request CallContext object, the client gains enhanced flexibility, allowing a single gRPC connection to interact with multiple databases. This refactoring improves resource utilization and simplifies client-side database switching. The changes also include the addition of a truncate_collection API for clearing collection data.

Highlights

  • Database Context Management: The handling of db_name has been refactored to be passed per API request via a new CallContext object, rather than being bound to the gRPC channel. This allows a single underlying gRPC connection to serve multiple databases.
  • Shared Connections for MilvusClient: Multiple MilvusClient and AsyncMilvusClient instances can now share the same underlying gRPC connection, even if they target different databases, as the database context is managed at the client instance level.
  • New CallContext Class: A new CallContext class has been introduced to encapsulate request-specific metadata, including db_name and client_request_id, streamlining how this information is propagated through the gRPC layer.
  • New truncate_collection API: A new API, truncate_collection, has been added to both synchronous and asynchronous gRPC handlers and exposed through MilvusClient, AsyncMilvusClient, Collection, and the utility module.
  • Deprecated reset_db_name: The reset_db_name method in gRPC handlers is now deprecated, with users directed to use MilvusClient.use_database() or AsyncMilvusClient.use_database() for managing database context.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant and well-executed refactoring to decouple the database name from the connection state. This allows multiple clients to share a single connection while operating on different databases, which is a great improvement. The introduction of CallContext to pass db_name on a per-request basis is a solid approach. The changes are extensive, touching client handlers, ORM classes, and utility functions. The use of _unbind_with_db to differentiate between ORM and MilvusClient connections is a clever way to manage this transition.

I've identified a critical bug in the asynchronous handler that would cause a runtime error, as well as some inconsistencies in how db_name is retrieved for backward compatibility, which could lead to subtle issues. My review comments focus on these points.

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 28.51153% with 341 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (2.6@3c0ab55). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pymilvus/milvus_client/milvus_client.py 7.79% 71 Missing ⚠️
pymilvus/milvus_client/async_milvus_client.py 10.00% 63 Missing ⚠️
pymilvus/client/grpc_handler.py 43.00% 57 Missing ⚠️
pymilvus/orm/collection.py 16.12% 52 Missing ⚠️
pymilvus/orm/utility.py 4.76% 40 Missing ⚠️
pymilvus/client/async_grpc_handler.py 68.42% 12 Missing ⚠️
pymilvus/decorators.py 0.00% 10 Missing ⚠️
pymilvus/orm/db.py 9.09% 10 Missing ⚠️
pymilvus/orm/partition.py 9.09% 10 Missing ⚠️
pymilvus/orm/index.py 0.00% 6 Missing ⚠️
... and 4 more
Additional details and impacted files
@@          Coverage Diff           @@
##             2.6    #3226   +/-   ##
======================================
  Coverage       ?   48.61%           
======================================
  Files          ?       70           
  Lines          ?    14777           
  Branches       ?        0           
======================================
  Hits           ?     7184           
  Misses         ?     7593           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mergify mergify bot added the ci-passed label Jan 23, 2026
silas.jiang added 2 commits January 23, 2026 11:42
Signed-off-by: silas.jiang <[email protected]>
Copy link
Contributor

@XuanYang-cn XuanYang-cn left a comment

Choose a reason for hiding this comment

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

/lgtm

@sre-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jac0626, XuanYang-cn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot sre-ci-robot merged commit e14a74a into milvus-io:2.6 Jan 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants