https://prefect.io logo
Title
s

Sunjay

10/26/2022, 2:36 PM
Hi folks, quick dumb question : to set to the type of parameter for a flow, do i just use type hints to set the type of parameters?
1
k

Khuyen Tran

10/26/2022, 3:17 PM
yes definitely. We use Pydantic to validate the type hints so most type hints should work. You can disable validating with
validate_parameters=False
s

Sunjay

10/27/2022, 8:44 AM
@Khuyen Tran I am able to set the type of the parameter as type hints, I am facing an issue when setting the parameter in the cloud UI , it automatically converts the list passed as a string. I am able to set the list in the UI but during runtime it takes the list as a string and fails the validation, even disabling validation is not going to resolve this. Can you please help me with this ?
k

Khuyen Tran

10/27/2022, 3:45 PM
Can you paste an example of how your flow code looks like?
s

Sunjay

10/28/2022, 1:42 PM
@flow(name='prod_pagespeed_metrics')
def pagespeed_metrics(columns:list, device_type:str='mobile', table_name:str='metrics', schema_name:str='dl_pagespeed_api', api_url:str='<https://www.googleapis.com/pagespeedonline/v5/runPagespeed',url_file_path:str='files/page_speed_urls.csv>'):
    url_list = get_url_list(url_file_path)
    category = 'performance'
    metrics = transform_pagespeed_api(url_list=url_list,
                                      device_type=device_type,
                                      category=category,
                                      api_key=google_pagespeed_api_key.get(),
                                       api_url=api_url)

    df_to_redshift(metrics, redshift_user.get(), redshift_password.get(),
                   table_name, redshift_db.get(), schema_name, redshift_host.get())
Hi @Khuyen Tran Sorry for the late reply, so basically , I am passing a list of columns as parameter, and when i change this list it shows up as string
also, had another question, How can reuse the same flow function with different parameter and have a deployment for each, For example, i want a flow deployment for device_type mobile and desktop. Can I reuse the same function ? or I need to create a function for each ?
k

Khuyen Tran

10/28/2022, 3:46 PM
I just deployed a flow with a list as a parameter:
from prefect import task, flow


@flow
def test_flow(l: list = [1, 2, 3]):
    assert isinstance(l, list)


if __name__ == "__main__":
    test_flow()
and changed the value of the parameter when running the deployment. It worked fine for me. I wonder if you change the value of the parameter through deployment?
🙌 1
Yes, you can use create_flow_run_from_deployment to create a flow run from a deployment with a custom parameter. Not sure if that answered your question
s

Sunjay

11/01/2022, 8:02 AM
@Khuyen Tran Thanks for this, i was indeed setting type in the function and actually passing the parameter in the UI overriding the default but my assumption was that once you provide a type hint, then it implicitly defines the type of the parameter and i should be able to pass list during run time. Anyway, let me double check this and get back to you