Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Sync compatible base #105

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion prefect_dbt/cli/configs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Dict, Optional

from prefect.blocks.core import Block
from prefect.utilities.asyncutils import sync_compatible
from pydantic import BaseModel, Field, SecretBytes, SecretStr


Expand Down Expand Up @@ -61,7 +62,8 @@ def _populate_configs_json(

return configs_json

def get_configs(self) -> Dict[str, Any]:
@sync_compatible
async def get_configs(self) -> Dict[str, Any]:
"""
Returns the dbt configs, likely used eventually for writing to profiles.yml.

Expand Down
11 changes: 9 additions & 2 deletions prefect_dbt/cli/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, Optional

from prefect.blocks.core import Block
from prefect.utilities.asyncutils import is_async_fn, sync_compatible

from prefect_dbt.cli.configs import GlobalConfigs, TargetConfigs

Expand Down Expand Up @@ -97,18 +98,24 @@ class DbtCliProfile(Block):
target_configs: TargetConfigs
global_configs: Optional[GlobalConfigs] = None

def get_profile(self) -> Dict[str, Any]:
@sync_compatible
async def get_profile(self) -> Dict[str, Any]:
"""
Returns the dbt profile, likely used for writing to profiles.yml.

Returns:
A JSON compatible dictionary with the expected format of profiles.yml.
"""
get_configs = self.target_configs.get_configs
if is_async_fn(get_configs):
target_configs = await get_configs()
else:
target_configs = get_configs()
profile = {
"config": self.global_configs.get_configs() if self.global_configs else {},
self.name: {
"target": self.target,
"outputs": {self.target: self.target_configs.get_configs()},
"outputs": {self.target: target_configs},
},
}
return profile