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

Add from_profiles_yml to dbt TargetConfigs #16178

Merged
merged 7 commits into from
Dec 4, 2024
Merged

Conversation

kevingrismore
Copy link
Contributor

@kevingrismore kevingrismore commented Dec 2, 2024

This is a starting point for converting dbt's profiles.yml contents into Prefect blocks programmatically. Includes a few utilities for getting the profile contents from an expected default or user-supplied directory.

Also fixes cloud tests for httpx==0.28.0 compatibility.

Example usage

profiles.yml

test:
  outputs:
    dev:
      type: duckdb
      path: dev.duckdb
      threads: 1

    prod:
      type: duckdb
      path: prod.duckdb
      threads: 4

  target: prod

test2:
  outputs:
    dev:
      type: duckdb
      path: dev.duckdb2
      threads: 1

    prod:
      type: duckdb
      path: prod.duckdb2
      threads: 4
    
  target: dev

test3:
  outputs:
    dev:
      dataset: demo
      job_execution_timeout_seconds: 300
      job_retries: 1
      keyfile: /path/to/keyfile.json
      location: US
      method: service-account
      priority: interactive
      project: sample_project
      threads: 1
      type: bigquery

    prod:
      dataset: prod
      job_execution_timeout_seconds: 300
      job_retries: 1
      keyfile: /path/to/keyfile.json
      location: US
      method: service-account
      priority: interactive
      project: sample_project
      threads: 1
      type: bigquery

  target: prod
>>> from prefect_dbt.cli.configs import TargetConfigs
>>> TargetConfigs.from_profiles_yml() # first profile, default target
TargetConfigs(extras=None, allow_field_overrides=False, type='duckdb', threads=4)
>>> TargetConfigs.from_profiles_yml("test2") # selected profile, default target
TargetConfigs(extras=None, allow_field_overrides=False, type='duckdb', threads=1)
>>> TargetConfigs.from_profiles_yml("test3", "dev") # selected profile, selected target
TargetConfigs(extras={'job_execution_timeout_seconds': 300, 'job_retries': 1, 'keyfile': '/path/to/keyfile.json', 'location': 'US', 'method': 'service-account', 'priority': 'interactive', 'project': 'sample_project'}, allow_field_overrides=False, type='bigquery', threads=1)
>>> TargetConfigs.from_profiles_yml("test3", "dev").get_configs()
{'job_execution_timeout_seconds': 300, 'job_retries': 1, 'keyfile': '/path/to/keyfile.json', 'location': 'US', 'method': 'service-account', 'priority': 'interactive', 'project': 'sample_project', 'type': 'bigquery', 'schema': 'demo', 'threads': 1}

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@github-actions github-actions bot added the docs label Dec 3, 2024
@kevingrismore kevingrismore marked this pull request as ready for review December 3, 2024 19:33
Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

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

one question about formatting but otherwise lgtm!

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

Nice!

src/integrations/prefect-dbt/tests/test_utilities.py Outdated Show resolved Hide resolved
@kevingrismore kevingrismore merged commit 47aa8f2 into main Dec 4, 2024
13 checks passed
@kevingrismore kevingrismore deleted the dbt-profiles-yml branch December 4, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants