hi, wanna ask a question if someone may know or ha...
# prefect-community
hi, wanna ask a question if someone may know or have some clues 😉 Appreciate for any help!🙌 In a flow run, we defined some parameters using
MyParams = Parameter('My_Param', default="my_input")
, in Prefect UI we can input some parameters to overwrite the default at run time, my question is: is there a way to get the run time parameter input (not the MyParams object, but the actual input)? In our case, the
is a list (where we pass a list of ids), we need to customize the flow run name by extracting each id from
and formalizing a new list (child flow run name) for
function to work. From what I understand and tested,
is a serialized object, to access its input first needs to deserialize it or using another way, we cannot just loop over it using
[i+'_customzied_string' for i in MyParams]
I encourage you to check examples on Discourse
Hey @Anna Geller, So I've been digging through some of these threads and not having much luck and I think I'm trying to address a similar problem as @Chu here. I'm trying to get the value from a Parameter and use it in the Prefect flow in version 1.2.4. With that, I'm seeing the documentation here which indicates the syntax that you mentioned in the other thread of
prefect.context.parameters.get("<parameter name>")
. However, when I try to use that syntax (in a flow which is triggered by the Prefect UI and run via a Universal Run agent) I am getting the error that the
attribute is not found as part of the
module. I see the documentation which indicates it should be there on the context at runtime, but here is a screenshot attached to this message that shows the intellisense code completion options I have in VS Code with the parameters function missing. Is there something I and @Chu might be missing in all this where the goal is to directly access the list used in the run in the rest of the code (i.e. if I run the flow with the defaults it grabs that and uses it in the rest of the code, but if I pass in a different value at runtime to the Prefect flow it will use the updated values in the rest of the code instead of the default values)
I think we are all trying to iterate a Parameter() after it creates, I find a great explanation of the nuances from Prefect CTO: https://stackoverflow.com/questions/64155793/is-it-possible-to-loop-over-a-prefect-parameter
I may not have emphasized that but passing data from parameter values works the same way as passing any data dependencies between tasks
So if I wanted to pass the data from the Parameter to the python variable
do I do
No, you would pass it as any Python object in functional programming
But Can we loop over a Parameter object? like
Copy code
with Flow("My flow") as flow:
    urls = Parameter("urls", default=['url1', 'url2', 'url3'])
    result = [url+'_string' for url in urls]
This behavior will give an error said, Task is not iterable.. I understand urls is a serialized Object, is there a way to diseralize it to retrieve the run time value (which maybe something different than default)
no looping is allowed in 1.0 unless you use mapping I believe that you should switch to 2.0 as soon as possible, 1.0 DAG requirement seems super confusing to you and it's no longer sth to worry about in 2.0
I understand, but just to confirm is mapping in Prefect1.0 can do the above stuff? I tried different methods in mapping, not work through. Would you mind showing me the code? We are in a slow switch, legacy System Still needs 1.0 to deliver some important data pipelines.
@Anna Geller, so we can loop over parameter object values in 2.0? We are in a position to make the migration, but just wanted to check first if there is documentation you could direct me to on this? Just did a quick search in the 2.0 docs and nothing jumps out initially in the examples that addresses this use case.
I didn't mean that 2.0 addresses any specific use case like that. I meant that in 2.0, it's easy to build such dynamic logic that dynamically combines parameter values in string manipulations and dynamically looping over things, as you mentioned, since 2.0 is essentially just Python with extra observability
Awww...gotcha. That is helpful context. Thank you 👍
🙌 1