Skip to content

Fix urljoin#996

Merged
joein merged 2 commits into
devfrom
fix-urljoin
May 21, 2025
Merged

Fix urljoin#996
joein merged 2 commits into
devfrom
fix-urljoin

Conversation

@joein

@joein joein commented May 20, 2025

Copy link
Copy Markdown
Member

#913

urljoin is joining base_url and url which is treated as an absolute path

therefore, if url starts with /, it might truncate prefix in base_url

This pr preprocess both host and url before sending a request.
Also, I've made host parameter mandatory in api_client and require it to be a string, since I don't see a case where it can be None or optional.

examples:

correct:

base = 'https://localhost:6333/api/v1/'
url = 'collections/collection_name'
urljoin(base, url)
>>> 'https://localhost:6333/api/v1/collections/collection_name'

incorrect:

base = 'https://localhost:6333/api/v1/'
url = '/collections/collection_name'
urljoin(base, url)
>>> 'https://localhost:6333/collections/collection_name'
base = 'https://localhost:6333/api/v1'
url = '/collections/collection_name'
urljoin(base, url)
>>> 'https://localhost:6333/collections/collection_name'
base = 'https://localhost:6333/api/v1'
url = 'collections/collection_name'
urljoin(base, url)
>>> 'https://localhost:6333/api/collections/collection_name'

@netlify

netlify Bot commented May 20, 2025

Copy link
Copy Markdown

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit bd2687a
🔍 Latest deploy log https://app.netlify.com/projects/poetic-froyo-8baba7/deploys/682cb1c8a87526000818855c
😎 Deploy Preview https://deploy-preview-996--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 May 20, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The constructors for the AsyncApis, SyncApis, and ApiClient classes in the API client code were modified to require a mandatory host parameter, removing its previous optional status. The logic for constructing request URLs in both synchronous and asynchronous request methods was updated to ensure the base host URL ends with a slash and the request path does not start with one, addressing issues with URL joining. In the test suite, additional assertions were added to verify the normalization of the rest_uri when different forms of the prefix parameter are provided during client initialization. No public API signatures were changed in the tests.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4285642 and bd2687a.

📒 Files selected for processing (2)
  • qdrant_client/http/api_client.py (5 hunks)
  • tests/test_qdrant_client.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Redirect rules - poetic-froyo-8baba7
  • GitHub Check: Header rules - poetic-froyo-8baba7
  • GitHub Check: Pages changed - poetic-froyo-8baba7
  • GitHub Check: Python 3.13.x on ubuntu-latest test
  • GitHub Check: Python 3.10.x on ubuntu-latest test
  • GitHub Check: Python 3.11.x on ubuntu-latest test
  • GitHub Check: Python 3.12.x on ubuntu-latest test
  • GitHub Check: Python 3.9.x on ubuntu-latest test
🔇 Additional comments (4)
qdrant_client/http/api_client.py (3)

25-25: Good improvement on parameter typing and constraints.

Making host a mandatory parameter with explicit str type adds clarity and prevents potential issues when host is None. This change is aligned with the PR objective which states "no valid case for it being None or optional".

Also applies to: 43-43, 68-68


87-91: Effective fix for the URL joining issue.

The implementation properly handles URL normalization by ensuring:

  1. The base URL (host) always ends with a slash
  2. The URL path never starts with a slash

This addresses the core issue where urljoin treats URLs starting with a slash as absolute paths, which could truncate the base URL's path prefix.


178-182: Consistent implementation in the async client.

The same URL normalization logic is properly applied to the async request method, ensuring consistent behavior between sync and async clients.

tests/test_qdrant_client.py (1)

156-181: Thorough test coverage for URL prefix normalization.

These tests comprehensively verify that URL prefix normalization works correctly with different combinations of leading and trailing slashes. The tests cover both initialization with url and host parameters, ensuring the fix works consistently across all client initialization patterns.

The test cases confirm that:

  1. For prefixes without trailing slashes ("api/v1", "/api/v1"), the resulting URI doesn't include a trailing slash
  2. For prefixes with trailing slashes ("api/v1/", "/api/v1/"), the trailing slash is preserved in the URI

This ensures the URL joining behavior aligns with the expected outcomes in all scenarios.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@joein joein merged commit 808b0ab into dev May 21, 2025
14 checks passed
joein added a commit that referenced this pull request Jun 16, 2025
* fix: fix urljoin usage

* fix: do not modify rest_uri, add tests
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