Adam Everington

11/22/2021, 1:17 PM
Hey guys, what do all these "add"'s mean? they clutter up the schematic quite badly, could we hide them?

Anna Geller

11/22/2021, 1:24 PM
@Adam Everington Add is a logical operator task created automatically by Prefect. If you add some number within your flow structure, it creates an Add task under the hood. You can definitely hide it if you want - it depends on how you structure your flow. When you move the addition into separate tasks, you could hide it. See the example here:
from prefect import task, Flow, Parameter

def return_some_number(x):
    return x

with Flow('Add one') as flow:
    result = Parameter('x', default=1) + 1
    nr = result + 1

And compare it to this:
from prefect import task, Flow, Parameter

def add_one(x):
    return x + 1

def add_one_again(x):
    return x + 1

with Flow('Add one') as flow:
    param = Parameter('x', default=1)
    result = add_one(param)


Adam Everington

11/22/2021, 2:28 PM
ok that makes sense, but i'm not manipulating the results of tasks within the flow, just passing them around... take my code here :
with Flow("Create-Postcode-Incode-Lookup"
    ,storage = Git(
        flow_path = "./ONS/",
    ,run_config=UniversalRun(labels=['Cloud01'])) as flow:

    working_directory = Parameter("Working Directory",default=r"/media/data0/prefect/ons",required=False)
    server = Parameter("RefData_Server",default="<|>",required=False)
    db = Parameter("RefData_Db",default="RefData",required=False)
    user = Parameter('SQL User Name', default='admin', required=False)

    pw = get_secret_value(user)      
    cnxn_string = get_cnxn_string(server,db,user,pw)

    url = get_download_url()
    files = download_postcode_directory(url, working_directory)
    postcode_file,parish_file = unzip_files(files, working_directory)
    postcodes = get_postcodes(postcode_file)
    parishes = get_parishes(parish_file)
    to_load = merge_datasets(postcodes, parishes)
    load = load_to_sql_server(to_load, cnxn_string, 'ONSInCodeLookup')

flow.schedule = schedules.Schedule(
    clocks=[CronClock("0 18 28 * *")]

and look at my flow visual I sent, the ref data param just gets passed to 1 task, that's it and yet it's showing 2 add operators? It's not a biggy... I'm just curious!

Anna Geller

11/22/2021, 3:42 PM
FYI: resolved via DM. For posterity: the issue was a missing @task decorator in the function get_cnxn_string
👍 1

Adam Everington

11/22/2021, 6:58 PM
yep... total noob move, @Anna Geller amazing as always
🙌 1