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

Credentials missing when using SnowflakeTargetConfigs in CLIProfile #125

Closed
1 task
sti0 opened this issue Feb 9, 2023 · 4 comments · Fixed by #127 or #128
Closed
1 task

Credentials missing when using SnowflakeTargetConfigs in CLIProfile #125

sti0 opened this issue Feb 9, 2023 · 4 comments · Fixed by #127 or #128

Comments

@sti0
Copy link

sti0 commented Feb 9, 2023

Expectation / Proposal

I define four block entities (Snowflake credentials, Snowflake connector, Snowflake target config and dbt CLI profile) and link them together. In this case credentials can be changed via block configuration.

I expect that the CLI profile holds the credential/connection information as well but it didn't. This is maybe related to the TargetConfigs which can't be linked to another block entity.

Traceback / Example

from prefect_snowflake.credentials import SnowflakeCredentials
from prefect_snowflake.database import SnowflakeConnector

from prefect_dbt.cli.credentials import DbtCliProfile
from prefect_dbt.cli.configs import SnowflakeTargetConfigs


if __name__ == "__main__":
    credentials = SnowflakeCredentials(
        user="user",
        password="password",
        account="account.region.aws",
        role="role",
    )
    credentials.save("sf-cred", overwrite=True)

    connector = SnowflakeConnector(
        schema="public",
        database="database",
        warehouse="warehouse",
        credentials=SnowflakeCredentials.load("sf-cred"),
    )
    connector.save("sf-conn", overwrite=True)

    target_configs = SnowflakeTargetConfigs(
        connector=SnowflakeConnector.load("sf-conn"), schema="TEST"
    )
    target_configs.save("dbt-targetconf", overwrite=True)

    dbt_cli_profile = DbtCliProfile(
        name="jaffle_shop",
        target="dev",
        target_configs=SnowflakeTargetConfigs.load("dbt-targetconf"),
    )
    dbt_cli_profile.save("example", overwrite=True)

    dbt_cli_profile = DbtCliProfile.load("example").get_profile()

    print(dbt_cli_profile)

Output:
{'config': {}, 'jaffle_shop': {'target': 'dev', 'outputs': {'dev': {'type': 'snowflake', 'schema': 'TEST', 'threads': 4}}}}

image

@ahuang11
Copy link
Contributor

ahuang11 commented Feb 9, 2023

Thanks for the details! I believe this has been fixed in #115.

image

@sti0
Copy link
Author

sti0 commented Feb 10, 2023

So we need to wait for a new release then.

@sti0
Copy link
Author

sti0 commented Feb 13, 2023

Hi @ahuang11 ,
I've tested the behavior with the latest main branch and this doesn't work for me when we specifiy a schema in the SnowflakeConnector (which is required) and in the Snowflake Target Config (which is optional).
This ends up in a ValueError: The keyword, schema, has already been provided in TargetConfigs; remove duplicated keywords to continue error.

As a workaround we could only specify it in Snowflake Connector but if we use the same Connector for different dbt Configs (or may for other things) it would be a better solution to overwrite the schema from Snowflake Connector with the schema from the target config.

Furthermore it seems that the private_key_path is not written in the profiles file as expected:

config: {}
iris:
  outputs:
    dev:
      account: account.region.azure
      authenticator: snowflake
      database: dbname
      private_key_path: !!python/object/apply:pathlib.PosixPath
      - /
      - workspace
      - tmp
      - rsa_key.p8
      role: development
      schema: abc
      threads: 8
      type: snowflake
      user: username
      warehouse: wh
  target: dev

which ends in an runtime error

Encountered an error:
Runtime Error
  
  dbt encountered an error while trying to read your profiles.yml file.
  
  Runtime Error
    Syntax error near line 8
    ------------------------------
    5  |       account: account.region.azure
    6  |       authenticator: snowflake
    7  |       database: dbname
    8  |       private_key_path: !!python/object/apply:pathlib.PosixPath
    9  |       - /
    10 |       - workspace
    11 |       - tmp
    
    Raw Error:
    ------------------------------
    could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:pathlib.PosixPath'
      in "<unicode string>", line 8, column 25

@ahuang11
Copy link
Contributor

Thank you for reporting this. I'll try to get this fixed soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants