https://prefect.io logo
Title
l

Laura Vaida

07/02/2021, 10:56 AM
Hi at all, im trying to use the following function:
For convenience, you can use the snowflake.sqlalchemy.URL method to construct the connection string and connect to the database. The following example constructs the same connection string from the previous example:

from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    account = 'myorganization-myaccount',
    user = 'testuser1',
    password = '0123456',
    database = 'testdb',
    schema = 'public',
    warehouse = 'testwh',
    role='myrole',
))
I want to create an engine with passing the input for URL with ** instead of putting every variable but I dont know how to write the input, it should be a str format that's what I tried, maybe you have an idea how input data should look like
###selecting order data
@task(log_stdout=True)
def create_engine(snowflake_salesforce):
    config = configparser.ConfigParser()
    engine=create_engine(URL(**config[snowflake_salesforce]))

with Flow('UWG-Mail') as flow:
    snowflake_credentials=PrefectSecret("Snowflake")
    connection=create_engine(snowflake_salesforce=snowflake_credentials)
but resulting in this error
[12:03 Uhr] Unexpected error: TypeError("unhashable type: 'dict'")
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner
    new_state = method(self, state, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 863, in get_task_run_state
    value = prefect.utilities.executors.run_task_with_timeout(
  File "/usr/local/lib/python3.8/site-packages/prefect/utilities/executors.py", line 298, in run_task_with_timeout
    return task.run(*args, **kwargs)  # type: ignore
  File "<input>", line 36, in create_engine
  File "/usr/local/lib/python3.8/configparser.py", line 959, in __getitem__
    if key != self.default_section and not self.has_section(key):
  File "/usr/local/lib/python3.8/configparser.py", line 668, in has_section
    return section in self._sections
TypeError: unhashable type: 'dict'
1
m

Marko Herkaliuk

07/02/2021, 11:22 AM
where you setup your secret? env or cloud?
l

Laura Vaida

07/02/2021, 11:23 AM
in the cloud
m

Marko Herkaliuk

07/02/2021, 11:23 AM
you put json in secret?
from prefect.client import Secret
config = Secret("Snowflake").get()

@task(log_stdout=True)
def create_engine(snowflake_cfg):
    engine=create_engine(URL(**snowflake_cfg))
with Flow('UWG-Mail') as flow:
    connection=create_engine(snowflake_salesforce=config)
try something like this
l

Laura Vaida

07/02/2021, 12:10 PM
thanks! do you know how to format the secrets for that?
m

Marko Herkaliuk

07/02/2021, 12:27 PM
i think like this
and after Secret("Snowflake").get() you have dict
l

Laura Vaida

07/02/2021, 12:39 PM
ahh maybe also possible as string?
m

Marko Herkaliuk

07/02/2021, 12:42 PM
Sure, you can add secret as string. Also you can run
from prefect.client import Secret
config = Secret("Snowflake").get()
from local env and saw what do you get
l

Laura Vaida

07/02/2021, 2:42 PM
can you give an example for the format? i don't get it 😄 sorry
k

Kevin Kho

07/06/2021, 1:37 PM
Did you get this one @Laura Vaida?
l

Laura Vaida

07/07/2021, 2:21 PM
yes, solved it, thanks 🙂