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

Drop Connection.schema use in DbtCloudHook #29166

Merged
merged 3 commits into from
Feb 2, 2023

Conversation

josh-fell
Copy link
Contributor

@josh-fell josh-fell commented Jan 25, 2023

Related: #28890 #29014

In version 2.3.1 of this provider, an fix was made to allow users to specify the entire tenant domain on their dbt Cloud instance rather than just the third-level (e.g. "my-tenant.domain.com" vs. "my-tenant.getdbt.com") via Connection.host. This was particular useful for other dbt Cloud regions other than the US. Backwards compat was still available via Connection.schema, but was noted as deprecated. Given other changes are being made to the provider, Connection.schema use to specify the dbt Cloud tenant domain should be dropped.

Also, there was a recent enhancement of DbtCloudRunJobOperator to include deferrable/async functionality. Unfortunately the tenant evaluation in the DbtCloudHook was outdated and didn't include the most recent change to properly handle domain specification. This PR consolidates the tenant eval logic to a common method to be used by both sync and async methods in the hook.

:param endpoint: Endpoint url to be requested.
:param include_related: Optional. List of related fields to pull with the run.
Valid values are "trigger", "job", "repository", and "environment".
"""
data: dict[str, Any] = {}
base_url = f"https://{tenant}.getdbt.com/api/v2/accounts/"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Old logic that is no longer valid.

if base_url and not base_url.endswith("/") and endpoint and not endpoint.startswith("/"):
url = base_url + "/" + endpoint
else:
url = (base_url or "") + (endpoint or "")
Copy link
Contributor Author

@josh-fell josh-fell Jan 25, 2023

Choose a reason for hiding this comment

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

Refactoring the branching here since the else would never be executed anyway.

@josh-fell josh-fell force-pushed the dbt-cloud-fix-tenant-async branch 2 times, most recently from 69b599c to 05ea8e3 Compare February 1, 2023 16:55
@staticmethod
def _get_tenant_domain(conn: Connection) -> str:
if conn.schema:
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

We can make a major release with the updated behavior rather than carry the deprecation further

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Do you think this warrants a newsfragment or does the major version increment imply something "newsworthy"?

Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to update version in provider.yaml to 3.0.0 and also update provider changelog with details of the breaking change (check Amazon provider change log for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right 🤦. I updated these now along with the PR title and description to make it clear what the significant change is in this PR.

@josh-fell josh-fell force-pushed the dbt-cloud-fix-tenant-async branch 2 times, most recently from 663fdb7 to c1cb663 Compare February 2, 2023 02:28
@josh-fell josh-fell changed the title Correct tenant eval within async logic of DbtCloudHook Drop Connection.schema use in DbtCloudHook Feb 2, 2023
Related: apache#28890 apache#29014

There was a recent enhancement of DbtCloudRunJobOperator to include deferrable/async functionality. Unfortunately the `tenant` evaluation in the DbtCloudHook was outdated and didn't include the most recent change to properly handle domain specification.

This PR consolidates the tenant eval logic to a common method to be used by both sync and async methods in the hook.
@josh-fell josh-fell merged commit 91c0ce7 into apache:main Feb 2, 2023
@josh-fell josh-fell deleted the dbt-cloud-fix-tenant-async branch February 2, 2023 16:42
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.

None yet

3 participants