Hi folks, I'm running into an issue when trying to...
# ask-community
g
Hi folks, I'm running into an issue when trying to register a flow which has some labels already added to the run config. Calling
flow.register()
on such a flow fails with error
'list' object has no attribute 'update'.
A reproducible example is in the thread. Has anybody come across this before or knows how to resolve it?
Here's the code:
Copy code
from prefect import Flow, task
from prefect.run_configs import UniversalRun

@task()
def hello_world():
    print("hello world")

with Flow("hello_world") as flow:
    hello = hello_world()

flow.run_config = UniversalRun()
flow.run_config.labels = ["foo", "bar"]
flow.register(project_name="test-project")
The stacktrace states that the problem occurs in the
obj.labels.update(self.storage.labels)
line of this section of `prefect.core.flow`:
Copy code
# add auto-labels for various types of storage
for obj in [self.environment, self.run_config]:
    if obj is not None:
        obj.labels.update(self.storage.labels)
        obj.labels.update(labels or ())
If I remove the
flow.run_config.labels = ["foo", "bar"]
line in my example code, the flow registers successfully.
n
Hi @Greg Roche - I'm going to open a ticket in the Core repo for this; in the meantime, try putting your labels on the register call (
flow.register(labels=["foo", "bar"])
)
@Marvin open "Flows with run config defined in code fail the registration step if labels are defined"
g
Thanks for the super-speedy reply 🙂
😄 1
n
Lmk if that works!
g
The workaround does allow the flow registration to succeed, thanks for that!
n
Great!
j
This is because
run_config.labels
is a set, not a list. When you manually assign things like this (rather than passing the labels to the run-config construtor) you're using the wrong type and breaking the internals. Try:
Copy code
flow.run_config = UniversalRun(labels=["foo", "bar"])
🤯 1
g
Got it, thanks a lot @Jim Crist-Harif - the example I posted was part of a bigger "flow preparation" routine we're using, where the run config was being instantiated first and then different labels were added to it afterwards depending on the use case of the flow. Changing that logic to first work out all the labels to apply, then instantiating the run config object, has fixed the root cause. Thanks again 🙂
👍 1