Skip to content

Conversation

Copy link

Copilot AI commented Dec 12, 2025

Description

raw_access_token performs blocking network calls when using OAuth authentication, which blocks the event loop in async applications (FastAPI, Django ASGI, etc.).

Changes

  • AsyncPipedream: Added async_raw_access_token async property for non-blocking token retrieval
  • Existing raw_access_token property preserved for backwards compatibility

Usage

from pipedream import AsyncPipedream

client = AsyncPipedream(
    client_id="...",
    client_secret="...",
    project_id="..."
)

# Non-blocking
token = await client.async_raw_access_token
Original prompt

This section details on the original issue you should resolve

<issue_title>Make raw_access_token async to support non-blocking use in async contexts</issue_title>
<issue_description>Description

Currently, accessing client.raw_access_token appears to perform a blocking network call to fetch the OAuth token. This blocks the event loop when used inside async applications.

Proposed solution:

  • Provide an async variant, e.g. await client.raw_access_token, or
  • Lazily initialize and refresh the token via an async mechanism under the hood when using AsyncPipedream.

This would make the SDK safer to use in async frameworks (e.g. FastAPI, Django ASGI) without blocking.</issue_description>

<agent_instructions>Please make sure that the change is backwards compatible</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Summary by CodeRabbit

  • New Features

    • Added asynchronous access token retrieval capability, enabling non-blocking token access in async contexts. Both standard and async client implementations now support this feature, with fallback to existing token retrieval methods when async tokens are unavailable.
  • Tests

    • Added comprehensive test coverage for token retrieval properties, including synchronous access, asynchronous retrieval paths, and OAuth-based initialization scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Two new asynchronous properties async_raw_access_token are introduced to both Pipedream and AsyncPipedream classes. These properties enable non-blocking token retrieval in async contexts by awaiting an internal async token or falling back to the existing synchronous access token. Corresponding test cases validate both sync and async token retrieval paths.

Changes

Cohort / File(s) Summary
Async token property implementation
src/pipedream/pipedream.py
Added async_raw_access_token property to Pipedream and AsyncPipedream classes for non-blocking asynchronous access token retrieval. Properties await internal async token when available, otherwise return raw_access_token.
Test coverage for token retrieval
tests/custom/test_client.py
Added test cases for sync raw_access_token property and async async_raw_access_token property retrieval paths, including OAuth flow validation with AsyncMock.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • New properties are straightforward async wrappers with fallback logic
  • Test cases follow existing patterns with minimal complexity
  • Small scope limited to token retrieval functionality

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions 'get_raw_access_token()' method but the actual implementation adds 'async_raw_access_token' property, not a 'get_raw_access_token()' method. Update the PR title to accurately reflect that async_raw_access_token properties were added instead of a get_raw_access_token() method.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR adds async token retrieval capability via async_raw_access_token property, addressing issue #238's requirement for non-blocking token access in async contexts.
Out of Scope Changes check ✅ Passed All changes are scoped to adding async token retrieval to Pipedream and AsyncPipedream classes with corresponding tests, directly addressing issue #238 requirements.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

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

…cking OAuth token fetching

Co-authored-by: jverce <5479513+jverce@users.noreply.github.com>
Copilot AI changed the title [WIP] Make raw_access_token async for non-blocking use Add async get_raw_access_token() method to AsyncPipedream Dec 12, 2025
Copilot AI requested a review from jverce December 12, 2025 22:41
@jverce
Copy link
Collaborator

jverce commented Dec 12, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2be15bf and 29355bb.

📒 Files selected for processing (2)
  • src/pipedream/pipedream.py (1 hunks)
  • tests/custom/test_client.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/pipedream/pipedream.py (1)
src/pipedream/core/client_wrapper.py (1)
  • _get_token (43-47)
tests/custom/test_client.py (1)
src/pipedream/pipedream.py (5)
  • AsyncPipedream (67-133)
  • Pipedream (16-64)
  • raw_access_token (60-64)
  • raw_access_token (111-120)
  • async_raw_access_token (123-133)
🪛 Ruff (0.14.8)
tests/custom/test_client.py

16-16: Possible hardcoded password assigned to argument: "access_token"

(S106)


17-17: Possible hardcoded password assigned to: "raw_access_token"

(S105)


22-22: Possible hardcoded password assigned to argument: "access_token"

(S106)


23-23: Possible hardcoded password assigned to: "raw_access_token"

(S105)


28-28: Possible hardcoded password assigned to argument: "access_token"

(S106)


30-30: Possible hardcoded password assigned to: "token"

(S105)


37-37: Possible hardcoded password assigned to argument: "client_secret"

(S106)


49-49: Possible hardcoded password assigned to: "token"

(S105)

🔇 Additional comments (6)
tests/custom/test_client.py (4)

1-6: LGTM!

The imports are appropriate for the new test cases. AsyncMock is correctly imported for mocking async token providers in the OAuth test.


14-17: LGTM!

Test correctly verifies synchronous token access for the Pipedream client.


20-23: LGTM!

Test correctly verifies the synchronous raw_access_token property on AsyncPipedream with a static token.


26-30: LGTM!

Test correctly verifies the new async_raw_access_token property with a static token. The async/await pattern is properly used.

src/pipedream/pipedream.py (2)

113-120: LGTM!

The updated docstring appropriately warns about potential blocking behavior when using OAuth and directs async application developers to the new async_raw_access_token property.


122-133: The implementation is complete and correct.

The async property properly initializes _async_token for OAuth flows (AsyncOAuthTokenProvider.get_token) in AsyncClient.__init__, while static tokens safely fall back to the synchronous raw_access_token property (which is non-blocking for string tokens). The test assertions at tests/custom/test_client.py:42 confirming _async_token is set for OAuth are valid. No naming inconsistency exists—the implementation correctly adds the async_raw_access_token property as intended.

Comment on lines 33 to 49
async def test_async_pipedream_async_raw_access_token_with_oauth() -> None:
"""Test AsyncPipedream async method with OAuth flow."""
client = AsyncPipedream(
client_id="test-client-id",
client_secret="test-client-secret",
project_id="test-project",
)

# The client should have _async_token set when using OAuth
assert client._client_wrapper._async_token is not None

# Mock the async token provider
client._client_wrapper._async_token = AsyncMock(return_value="mocked-oauth-token")

# Test the async method
token = await client.async_raw_access_token
assert token == "mocked-oauth-token"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Search for _async_token initialization and usage
echo "=== Searching for _async_token initialization ==="
rg -nP --type=py '_async_token\s*=' 

echo -e "\n=== Searching for _async_token references ==="
rg -nP --type=py '_async_token' -C3

echo -e "\n=== Locating AsyncClientWrapper class ==="
ast-grep --pattern 'class AsyncClientWrapper { $$$ }'

echo -e "\n=== Searching for AsyncClientWrapper in Python files ==="
rg -nP --type=py 'class AsyncClientWrapper'

Repository: PipedreamHQ/pipedream-sdk-python

Length of output: 2919


🏁 Script executed:

#!/bin/bash

echo "=== Checking AsyncPipedream constructor ==="
rg -nP --type=py 'class AsyncPipedream' -A 30

echo -e "\n=== Checking how _async_token is set during initialization ==="
rg -nP --type=py 'async_token' -B2 -A2 | head -60

Repository: PipedreamHQ/pipedream-sdk-python

Length of output: 4973


Remove the assertion on line 42 to avoid testing private implementation details.

The assertion assert client._client_wrapper._async_token is not None directly accesses a private attribute (_async_token), creating tight coupling to implementation details. Since the test verifies the actual behavior through the public API at line 48 (token = await client.async_raw_access_token), the assertion is redundant. If OAuth initialization fails, the behavioral test will catch it when attempting to retrieve the token. Removing line 42 makes the test cleaner and less dependent on internal state.

Note: Line 45 (mocking _async_token) is acceptable since there is no public setter and mocking is necessary to test the async token provider behavior.

🧰 Tools
🪛 Ruff (0.14.8)

37-37: Possible hardcoded password assigned to argument: "client_secret"

(S106)


49-49: Possible hardcoded password assigned to: "token"

(S105)

🤖 Prompt for AI Agents
In tests/custom/test_client.py around lines 33 to 49, remove the assertion that
accesses the private attribute (the line asserting
client._client_wrapper._async_token is not None) to avoid testing private
implementation details; simply delete that assert line and keep the mock of
_async_token and the behavioral await/verify of client.async_raw_access_token
as-is.

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.

Make raw_access_token async to support non-blocking use in async contexts

2 participants