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: (CDK) (HttpRequester) - fix trailing slash for url_base when no path has been provided #412

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

bazarnov
Copy link
Contributor

@bazarnov bazarnov commented Mar 12, 2025

What

Resolving regression after:

Resolving OC:

How

  • moved from using the os.path.join() in the _join_url() method, use it when the path is provided and there is no / at the end of the url_base to join the URL parts correctly

User Impact

No impact is expected. This is not a breaking change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the construction and formatting of URLs to ensure consistent handling of trailing slashes, resulting in more predictable URL outputs.
  • Tests
    • Updated verification checks to align with the refined URL formatting, ensuring that all endpoints now meet the expected behavior.

@bazarnov bazarnov self-assigned this Mar 12, 2025
@Copilot Copilot bot review requested due to automatic review settings March 12, 2025 15:57
@github-actions github-actions bot added bug Something isn't working security labels Mar 12, 2025

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a regression in URL joining logic for the HttpRequester by adjusting how the trailing slash for the url_base is handled when no explicit path is provided. The key changes are:

  • Removing the use of os.path.join in get_url_base to preserve the evaluated string.
  • Updating _join_url to return the url_base as-is when the path is empty, with documentation examples revised accordingly.
  • Adjusting unit tests to reflect the new behavior for trailing slashes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
airbyte_cdk/sources/declarative/requesters/http_requester.py Removes os.path.join usage in get_url_base and updates _join_url behavior for trailing slash handling
unit_tests/sources/declarative/requesters/test_http_requester.py Updates expected URL values in assertions to match the revised logic
Comments suppressed due to low confidence (2)

airbyte_cdk/sources/declarative/requesters/http_requester.py:134

  • Removing os.path.join changes the cross-platform URL formatting behavior; please confirm that self._url_base.eval consistently returns the URL without an undesired trailing slash across different environments.
return os.path.join(self._url_base.eval(self.config, **interpolation_context), EmptyString)

airbyte_cdk/sources/declarative/requesters/http_requester.py:378

  • The updated _join_url method now returns url_base as-is for an empty path, which may result in preserving an unexpected trailing slash; ensure that this updated behavior is fully aligned with all documented examples and use cases.
if path == EmptyString or path is None:
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

The changes update the URL handling logic in the HTTP requester. In the source file, the get_url_base method now converts the evaluated URL base directly to a string, removing the previous use of os.path.join with an empty string. The _join_url method has been revised to preserve the trailing slash when the path is empty and to conditionally append a slash when the base URL lacks one. Corresponding test cases were modified to expect URLs without trailing slashes.

Changes

File(s) Summary of Changes
airbyte_cdk/sources/declarative/requesters/http_requester.py Modified get_url_base to convert URL base directly to string; updated _join_url to handle empty paths by preserving the trailing slash and appending a slash when the base URL is missing it.
unit_tests/sources/declarative/requesters/test_http_requester.py Updated test assertions to expect URLs without trailing slashes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant HttpRequester

    Caller->>HttpRequester: get_url_base(...)
    Note right of HttpRequester: Convert evaluated URL base to string
    HttpRequester-->>Caller: Return URL base

    Caller->>HttpRequester: _join_url(url_base, path)
    alt path is empty
        Note right of HttpRequester: Retain trailing slash in base URL
        HttpRequester-->>Caller: Return base URL
    else base missing trailing slash
        HttpRequester->>HttpRequester: Append slash to base URL
        HttpRequester-->>Caller: Return joined URL
    end
Loading

Suggested reviewers

  • natikgadzhi
  • artem1205

Would you like to review the sequence diagram and labels to ensure they match your expectations, wdyt?

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 2f8d3dc and 649c6d0.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/requesters/http_requester.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • airbyte_cdk/sources/declarative/requesters/http_requester.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Analyze (python)
  • GitHub Check: SDM Docker Image Build

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

Copy link
Contributor

@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 (2)
airbyte_cdk/sources/declarative/requesters/http_requester.py (2)

368-369: Docstring doesn't match the implementation.

The docstring incorrectly states that trailing slashes are removed when the path is empty, but the implementation actually preserves them. Would you consider updating the docstring to accurately reflect the new behavior?

-            - If the path is an empty string or None, the method returns the base URL with any trailing slash removed.
+            - If the path is an empty string or None, the method returns the base URL as is, preserving any trailing slash.

377-385: Fixed trailing slash handling for URL_base when no path is provided.

The implementation now:

  1. Preserves the trailing slash when path is empty (fixing the regression)
  2. Only applies os.path.join() when adding a trailing slash to url_base that doesn't have one

This implementation aligns with the PR objectives to fix the trailing slash issue.

Consider using a more direct approach for adding a trailing slash in line 384, which would be clearer and avoid potential cross-platform inconsistencies with os.path.join():

-            if not url_base.endswith("/"):
-                url_base = os.path.join(url_base, EmptyString)
+            if not url_base.endswith("/"):
+                url_base = url_base + "/"

What do you think?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 741a2a0 and 2f8d3dc.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/requesters/http_requester.py (2 hunks)
  • unit_tests/sources/declarative/requesters/test_http_requester.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
unit_tests/sources/declarative/requesters/test_http_requester.py (2)

124-124: Test assertion updated to match implementation change.

The assertion now expects a URL without a trailing slash, aligning with the updated behavior in the get_url_base() method.


148-148: Test expectations updated for consistency.

These test case updates ensure the expected behavior matches the implementation changes for URL base handling without trailing slashes.

Also applies to: 150-150

airbyte_cdk/sources/declarative/requesters/http_requester.py (1)

135-135: Simplified URL base handling.

The method now directly returns the string representation of the evaluated URL base without using os.path.join(), addressing the issue mentioned in the PR objectives.

@bazarnov bazarnov requested a review from lmossman March 12, 2025 18:15
Copy link
Contributor

@lmossman lmossman left a comment

Choose a reason for hiding this comment

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

Logic makes sense to me, though I did not test this myself

@bazarnov bazarnov merged commit 2607bcf into main Mar 12, 2025
25 checks passed
@bazarnov bazarnov deleted the baz/cdk/fix-url-base-trailing-slash-when-no-path branch March 12, 2025 21:12
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.

2 participants