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 declarative oauth initialization #32967

Merged
merged 10 commits into from
Jan 9, 2024
Merged

Conversation

girarda
Copy link
Contributor

@girarda girarda commented Nov 30, 2023

What

This is a blocker for updating source-quickbooks to the latest version of the cdk.

How

  • Call super().__init__() to initialize the parent paremeters

Recommended reading order

  1. airbyte-cdk/python/airbyte_cdk/sources/declarative/auth/oauth.py
  2. airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py

Copy link

vercel bot commented Nov 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
airbyte-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2024 8:48pm

@octavia-squidington-iii octavia-squidington-iii added the CDK Connector Development Kit label Nov 30, 2023
@@ -80,7 +80,7 @@ def build_refresh_request_body(self) -> Mapping[str, Any]:
"refresh_token": self.get_refresh_token(),
}

if self.get_scopes:
if self.get_scopes():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brianjlai flagging this because this is a change in behavior. The existing condition always evaluates to true since the method always exists. I'm pretty sure this is a bug but I don't know how to verify the new behavior works for all possible connectors (including connector-builder connectors)...

Would it make more sense to remove the condition to keep the existing behavior but make the code clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

So basically this would mean retaining the existing behavior means that we can set a token with a payload where scopes = []?

I'd be willing to take the risk and say we only set the scopes payload field if theres at least one to pass along. So how you have it seems fine and was the original intent of the code

@marcosmarxm
Copy link
Member

@girarda can we merge this?

self.client_id = InterpolatedString.create(self.client_id, parameters=parameters)
self.client_secret = InterpolatedString.create(self.client_secret, parameters=parameters)
def __post_init__(self, parameters: Mapping[str, Any]) -> None:
super().__init__()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the fix. Other changes are necessary to please mypy

Copy link
Contributor

@brianjlai brianjlai left a comment

Choose a reason for hiding this comment

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

a few questions which i think are related to fixes for mypy. the change and the open question you had seem fine to me!

@@ -80,7 +80,7 @@ def build_refresh_request_body(self) -> Mapping[str, Any]:
"refresh_token": self.get_refresh_token(),
}

if self.get_scopes:
if self.get_scopes():
Copy link
Contributor

Choose a reason for hiding this comment

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

So basically this would mean retaining the existing behavior means that we can set a token with a payload where scopes = []?

I'd be willing to take the risk and say we only set the scopes payload field if theres at least one to pass along. So how you have it seems fine and was the original intent of the code

self.client_secret = InterpolatedString.create(self.client_secret, parameters=parameters)
def __post_init__(self, parameters: Mapping[str, Any]) -> None:
super().__init__()
self._token_refresh_endpoint = InterpolatedString.create(self.token_refresh_endpoint, parameters=parameters)
Copy link
Contributor

Choose a reason for hiding this comment

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

was mypy complaining about the non-private fields for refresh, client id and client secret or some name collision? I noticed you made this change, but not to the access_token_name, expires_in_name, and grant_type which follow the same naming convention, so curious why this was needed for only some?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. taking the refresh token as an example, if using the public variable, mypy complains on line 82 because the value is expected to be an interpolated string, not an Union[str, InterpolatedString]

@girarda girarda merged commit c8ca4b1 into master Jan 9, 2024
22 checks passed
@girarda girarda deleted the alex/fix_declarative_oauth branch January 9, 2024 01:40
jatinyadav-cc pushed a commit to ollionorg/datapipes-airbyte that referenced this pull request Feb 26, 2024
Co-authored-by: girarda <girarda@users.noreply.github.com>
jatinyadav-cc pushed a commit to ollionorg/datapipes-airbyte that referenced this pull request Feb 26, 2024
Co-authored-by: girarda <girarda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants