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

fix: model fields set and model config access #918

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

joein
Copy link
Member

@joein joein commented Mar 5, 2025

due to incorrect access to model_fields_set the following upsert was failing in pydantic v1

from qdrant_client import QdrantClient, models

if __name__ == '__main__':
    client = QdrantClient(":memory:")
    collection_name = "test"

    # Create collection with sparse vector support
    client.create_collection(
        collection_name=collection_name,
        sparse_vectors_config={
            "text": models.SparseVectorParams(),
        },
    )

    client.upsert(
        collection_name=collection_name,
        points=[
            models.PointStruct(
                id=1,
                vector={
                    "text": models.SparseVector(
                        indices=[1, 3, 5, 6],
                        values=[0.1, 0.2, 0.3, 0.4],
                    )
                },
            )
        ],
    )

Verified

This commit was signed with the committer’s verified signature. The key has expired.
dtzWill Will Dietz
Copy link

coderabbitai bot commented Mar 5, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new function, model_config, in the compatibility module to uniformly retrieve a Pydantic model's configuration. The function checks the PYDANTIC_V2 flag and either returns model.model_config or constructs a dictionary from model.__config__. Additionally, the PR updates the type inspector to use a function call to model_fields_set—imported from the compatibility module—instead of directly accessing the field set attribute. Similarly, the logic in the inspection cache population tool now accesses model configurations by calling model_config(model) rather than directly reading an attribute. These changes standardize the retrieval of model configuration and field details across different parts of the codebase while accounting for variations in Pydantic versions.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
qdrant_client/_pydantic_compat.py (1)

56-57: Consistent spacing

The added blank lines maintain the module's consistent style of separating function definitions, which is good for readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64311d3 and a2ed898.

📒 Files selected for processing (3)
  • qdrant_client/_pydantic_compat.py (1 hunks)
  • qdrant_client/embed/type_inspector.py (2 hunks)
  • tools/populate_inspection_cache.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Python 3.13.x on ubuntu-latest test
  • GitHub Check: Python 3.12.x on ubuntu-latest test
  • GitHub Check: Python 3.11.x on ubuntu-latest test
  • GitHub Check: Python 3.10.x on ubuntu-latest test
  • GitHub Check: Python 3.9.x on ubuntu-latest test
🔇 Additional comments (5)
qdrant_client/embed/type_inspector.py (2)

5-5: Good addition of import from compatibility module

This import allows the code to use the model_fields_set function from the compatibility layer, which handles differences between Pydantic v1 and v2.


66-66: Proper implementation of Pydantic version compatibility

Replacing direct access to member.model_fields_set with model_fields_set(member) ensures compatibility with both Pydantic v1 and v2. This is essential since in v1, field sets are accessed via __fields_set__ while in v2 they're accessed via model_fields_set.

tools/populate_inspection_cache.py (2)

9-9: Good addition of import from compatibility module

Adding the import for model_config enables the code to use the compatibility function for accessing model configurations consistently across Pydantic versions.


44-45: Correct implementation of Pydantic version compatibility

Replacing direct access to model.model_config with model_config(model) ensures the code works with both Pydantic v1 (which uses __config__) and v2 (which uses model_config). The subsequent check for the "extra" configuration property is maintained correctly.

qdrant_client/_pydantic_compat.py (1)

58-62: Well-implemented compatibility function for model config access

The new model_config function follows the established pattern in this compatibility module. It correctly handles the difference between Pydantic v1 (where configuration is accessed via __config__) and v2 (where it's accessed via model_config).

The implementation gracefully returns a dictionary representation regardless of the Pydantic version, ensuring consistent behavior throughout the codebase.

Copy link

netlify bot commented Mar 5, 2025

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit a2ed898
🔍 Latest deploy log https://app.netlify.com/sites/poetic-froyo-8baba7/deploys/67c8755b53f0010008af0ca4
😎 Deploy Preview https://deploy-preview-918--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 site configuration.

@joein joein requested a review from generall March 5, 2025 16:40
@joein joein merged commit 374e115 into master Mar 5, 2025
14 checks passed
joein added a commit that referenced this pull request Mar 16, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
dtzWill Will Dietz
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.

None yet

2 participants