Anyone know what it means when you attempt to regi...
# ask-community
j
Anyone know what it means when you attempt to register a flow with
Copy code
prefect register
and you don't get any error/warning messages but only:
Copy code
================= 0 registered, 1 skipped =================
k
Hey Jay, what
prefect register
commands did you use? Is the flow simple enough to share (remove any credentials)? Did you register the flow before?
j
Hi Kevin, The flow not simple enough to share. I managed to register and run approx 10 flows several few minutes ago but now something has changed.
Would like to know where I should look for logs?
How does one troubleshoot this matter?
Might be related to my trying to use Parameter()
My impression is that Parameters can be declared outside of the flow definition e.g.:
Copy code
bucket_name = Parameter("bucket_name", default=DEFAULT_BUCKET_NAME)
Correct?
k
No they can’t be. The Parameter is also a task. Does it work when you do
flow.run()
?
j
When I move the declarations inside of the Flow definition, I now get this to STDOUT:
Copy code
/usr/lib/python3.8/contextlib.py:120: UserWarning: Tasks were created but not added to the flow: {<Parameter: outdir>, <Parameter: experiment_bucket_name>, <Parameter: scratch_bucket_name>}. This can occur when `Task` classes, including `Parameters`, are instantiated inside a `with flow:` block but not added to the flow either explicitly or as the input to another task. For more information, see <https://docs.prefect.io/core/advanced_tutorials/task-guide.html#adding-tasks-to-flows>.
  next(self.gen)
k
I think this is saying that the
bucket_name
is not used in a downstream task. Did you pass it to a downstream task inside your flow?
Oh you did but the
outdir
,
scratch_bucket_name
are the ones giving you issues
j
Okay (yes I did pass bucket_name to downstream tasks). Ah, yes: outdir and scratch_bucket_name are no longer passed downstream (just global scope). I think some previous errors prevented these messages from propagating up? I'll try now and follow-up. Thank you!
What is the proper way to do this?
Copy code
outdir = Parameter("outdir", default=DEFAULT_OUTDIR)
I get an exception in the Flow definition block where it gets to this line:
Copy code
if not os.path.exists(outdir):
    pathlib.Path(outdir).mkdir(parents=True, exist_ok=True)
this is the error:
Copy code
TypeError: stat: path should be string, bytes, os.PathLike or integer, not Parameter
k
Yeah run the Parameter is undefined until run time. That os.path.exists(outdir) is trying to resolve as build time. The approach here would be to wrap that code in a
Task
j
Maybe the code should not allow the user to specify the output directory as a Parameter.
k
and then pass your parameter to the Task
let me type an example for you
🙂 1
Copy code
from prefect import task

@task
def create_dir(outdir):
    if not os.path.exists(outdir):
        pathlib.Path(outdir).mkdir(parents=True, exist_ok=True)
    return

with Flow('test') as flow:
    outdir = Parameter('outdir', default="/dir/dir")
    create_dir(outdir)
j
Thank you. I'll give it a try.
k
think of it was your
Flows
should only contain
Tasks
and
Parameter
is a
Task
itself
j
Thank you. 👍 Seems to be working. Would be helpful to get some diagnostic info when using prefect register where the result is: 0 registered, 1 skipped. Would be helpful to know why the 1 flow was skipped.
k
did it register now that the errors were fixed or is that still an issue?
j
Feels like hit or miss (esp. since no messages). flow.run() made some progress - encountered next error. meanwhile, prefect register continues to give 0 registered, 1 skipped with no other info
k
Yeah I will ask the core team about that and see if we can have more descriptive logs around that.
🙌 1
z
Hey @Jay Sundaram -- what happens if you run
prefect register --force
?
j
@Zanie: I'll try it next time I get that outcome (0 registered, 1 skipped). Thank you.
Tried --force and it worked. But I still don't know what root cause is. Is there more info in a log file somewhere?
k
Hey @Jay Sundaram, the root cause is metadata not changing for the flow. We’ll be adding a more descriptive message to the CLI
j
thank you. that will help!