Hi, can someone help me with this error? <https://...
# ask-community
j
Hi, can someone help me with this error? https://cloud.prefect.io/stockwell/flow-run/f82f5a87-e196-4019-a332-d27355fda2dd?logs=
Copy code
KeyError: 'Task slug disable_sound_on_mixer_error_stores-1 not found in the current Flow; this is usually caused by changing the Flow without reregistering it with the Prefect API.'
The slug is a transformation of the name of a flow. Prefect replaced the hyphens with
_
and added
-1
to the end. The error is happening when trying to run a different flow. Both flows are defined in the same Python source file. Both flows were registered with the latest code, contrary to the suggestion in the error message.
đź‘€ 1
z
can you share the flow code?
j
Copy code
@task
def search_logs_for_mixer_error():
    pass # Redacted

@task
def disable_sound_on_mixer_error_stores():
    pass # Redacted

with OurFlow('search-logs-for-mixer-error',
             Schedule(clocks=[CronClock('0 20 * * *')])) as flow_search_logs:
    search = search_logs_for_mixer_error()

with OurFlow('disable-sound-on-mixer-error-stores',
             Schedule(clocks=[CronClock('0 23 * * *')])) as flow:
    disable = disable_sound_on_mixer_error_stores()
The registration script:
Copy code
#!/usr/bin/env python
import sys
import os

if len(sys.argv) != 2:
    print('Usage: %s <filename>' % sys.argv[0])
    sys.exit(1)

MODULE_PATH = sys.argv[1]
MODULE_NAME = "flow_module"
import importlib
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)

for flow in [ getattr(module, var) for var in dir(module) if var.startswith('flow') ]:
    flow.register(project_name='our-project')
I'm just going to put each flow in a separate file. I suppose Prefect just can't handle two flows in one file.
z
i would think it can, I assume its looking for the object type in globals or something like that. I personally find the cli easier to use for registration than a python script.
j
I don't remember what happened when I attempted to use the CLI.
Perhaps I never saw anything about the CLI in the tutorial.
z
this is what mine looks like
Copy code
prefect backend cloud
prefect auth login --token $PREFECT_API_TOKEN
prefect register --project my-project -p /path/to/my/flows/
j
The --help suggests that you also have to know the name of the flow.
z
-p lets you pass in a directory
j
-p is an alias for --project according to --help.
z
you on an older version maybe?
Copy code
--project TEXT     The name of the Prefect project to register this flow in.
                     Required.

  -p, --path TEXT    A path to a file or a directory containing the flow(s) to
                     register. May be passed multiple times to specify
                     multiple paths.

  -m, --module TEXT  A python module name containing the flow(s) to register.
                     May be the full import path to a flow. May be passed
                     multiple times to specify multiple modules.

  -j, --json TEXT    A path or URL to a JSON file created by `prefect build`
                     containing the flow(s) to register. May be passed
                     multiple times to specify multiple paths. Note that this
                     path may be a remote url (e.g. <https://some>-
                     url/flows.json).

  -n, --name TEXT    The name of a flow to register from the specified
                     paths/modules. If provided, only flows with a matching
                     name will be registered. May be passed multiple times to
                     specify multiple flows. If not provided, all flows found
                     on all paths/modules will be registered.

  -l, --label TEXT   A label to add on all registered flow(s). May be passed
                     multiple times to specify multiple labels.

  -f, --force        Force flow registration, even if the flow's metadata is
                     unchanged.

  --watch            If set, the specified paths and modules will be monitored
                     and registration re-run upon changes.

  -h, --help         Show this message and exit.
j
I can't tell. There's no
prefect --version
.
z
pip show prefect
looks like
prefect version
is the cli command
j
I found it. Upgrading will be a lot of work.
What version of
click
does Prefect require? In the past I've found that it's very sensitive to the version of this library that gets installed.
Ok, thanks. I'll see if this works.
k
Hey @Jeremy Phelps, I’m not sure what version you’re on but I think the hard requirement is below 8.0.
j
I can't upgrade Prefect because it requires Pendulum 2.0, which is incompatible with the
enum34
library. A ton of my app's dependencies install enum34.
k
What is your current version? I’m not sure that this registration issue is related to the version (as long as you’re above 0.14)
j
0.14.22
I upgraded from 0.14.2.
k
You’re very up to date. Let me try this setup and see if I run into issues.
j
All my flows started failing due to Prefect referencing
pendulum.DateTime
after the upgrade.
k
Will try on 0.14.2
z
if youre using enum34, are you still running python 2? I wouldn’t really expect prefect to work on an officially deprecated version
k
I can’t replicate the error. Here is my sample flow. I used your exact registration script on Prefect 0.14.2. I included underscores in task names, hypens in flow names, tried changing tasks and re-registering. I also tried the flows having common tasks and all of these work on 0.14.2 when registered from the same file.
Copy code
from prefect import Flow, task, Task
import prefect

@task
def abc_abc_abc_abc():
    return 1

@task
def bcd_bcd_bcd_bcd():
    return 1

with Flow("testing-abc-abc") as flow_abc:
    abc_abc_abc_abc()
    bcd_bcd_bcd_bcd()

with Flow("testing-bcd-bcd") as flow:
    bcd_bcd_bcd_bcd()
j
I applied a hack to my production environment to prevent
enum34
from getting installed. That way I should be able to upgrade to Pendulum 2.0.0 without difficulty.