Peter Kim
11/09/2023, 5:25 PM@flow
def a_flow(
arg1: list[str]
) -> bool:
# etc.
pass
and I get this error:
TypeError: issubclass() arg 1 must be a class
Peter Kim
11/09/2023, 5:26 PMlist[str]
isn't a classMarvin
11/09/2023, 5:26 PM@flow
decorator. When a function becomes a flow, its behavior changes, giving it several advantages, including the ability to have persistent state and type-validated input arguments.
However, the error you're seeing, TypeError: issubclass() arg 1 must be a class
, is not directly related to Prefect. It's a Python error that occurs when the first argument to the issubclass()
function is not a class. It's possible that this error is being raised because of how you're trying to use a list as an argument in your flow definition.
Here's an example of how you can define a flow that takes a list as an argument:
from prefect import Flow, Parameter
def a_flow(arg1: list):
# your flow logic here
pass
with Flow('My Flow') as flow:
arg1 = Parameter('arg1', default=[])
result = a_flow(arg1)
In this example, arg1
is a parameter that defaults to an empty list. You can pass a list to your flow when you run it.
If you're still having trouble, could you provide more context or a more complete example of your code? That would help me give a more precise answer.Peter Kim
11/09/2023, 5:32 PMNate
11/09/2023, 5:38 PMah... it seems like there's no way to annotate flow inputs as typed containers, but I can annotate task inpuhts like so
In [1]: from prefect import flow
In [2]: @flow
...: def foo(anything: list[str]) -> list[str]:
...: return anything
...:
In [3]: foo(['a', 'b', 'c'])
11:38:21.766 | INFO | prefect.engine - Created flow run 'rampant-chowchow' for flow 'foo'
11:38:22.591 | INFO | Flow run 'rampant-chowchow' - Finished in state Completed()
Out[3]: ['a', 'b', 'c']
Nate
11/09/2023, 5:38 PMPeter Kim
11/09/2023, 5:39 PMPeter Kim
11/09/2023, 5:39 PMNate
11/09/2023, 5:39 PMflow
?Peter Kim
11/09/2023, 5:39 PMPeter Kim
11/09/2023, 5:40 PMPeter Kim
11/09/2023, 5:40 PMprefect.flow
is the only flow
variable in the namespacePeter Kim
11/09/2023, 5:42 PMfrom prefect import flow
@flow
def mini_flow(arg1: list[str]) -> str:
print(arg1)
return ",".join(arg1)
if __name__ == "__main__":
mini_flow.serve(name="mini-flow")
Peter Kim
11/09/2023, 5:42 PMNate
11/09/2023, 5:42 PMPeter Kim
11/09/2023, 5:43 PMNate
11/09/2023, 5:43 PMNate
11/09/2023, 5:43 PMPeter Kim
11/09/2023, 5:43 PMPeter Kim
11/09/2023, 5:44 PMrun_flow.py
and I call python run_flow.py
Peter Kim
11/09/2023, 5:44 PMPeter Kim
11/09/2023, 5:44 PMPeter Kim
11/09/2023, 5:44 PMNate
11/09/2023, 5:44 PMPeter Kim
11/09/2023, 5:45 PMpython run_flow.py
scriptPeter Kim
11/09/2023, 5:45 PMNate
11/09/2023, 5:45 PMprefect version
(contains some other stuff besides just the version)Peter Kim
11/09/2023, 5:46 PMNate
11/09/2023, 5:47 PMNate
11/09/2023, 5:48 PMPeter Kim
11/09/2023, 5:48 PMNate
11/09/2023, 5:48 PMPeter Kim
11/09/2023, 5:50 PMTraceback (most recent call last):
File "/Users/big-n00b/local-repo/run_flow.py", line 5, in <module>
def mini_flow(arg1: list[str]) -> str:
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/flows.py", line 1339, in flow
Flow(
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/context.py", line 185, in __register_init__
__init__(__self__, *args, **kwargs)
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/flows.py", line 299, in __init__
self.parameters = parameter_schema(self.fn)
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/utilities/callables.py", line 322, in parameter_schema
if HAS_PYDANTIC_V2 and has_v2_model_as_param(signature):
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/_internal/pydantic/v2_schema.py", line 22, in has_v2_model_as_param
return any(
File "/Users/big-n00b/Library/Caches/pypoetry/virtualenvs/my-project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/_internal/pydantic/v2_schema.py", line 24, in <genexpr>
or (inspect.isclass(p.annotation) and issubclass(p.annotation, V2BaseModel))
File "/Users/big-n00b/.pyenv/versions/3.10.12/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
Nate
11/09/2023, 5:50 PMNate
11/09/2023, 5:50 PMpip install 'pydantic<2'
and try againPeter Kim
11/09/2023, 5:52 PMPeter Kim
11/09/2023, 5:53 PMNate
11/09/2023, 5:53 PMPeter Kim
11/09/2023, 5:53 PMNate
11/09/2023, 5:54 PMPeter Kim
11/09/2023, 5:54 PMNate
11/09/2023, 5:54 PMNate
11/09/2023, 5:59 PM(bleeding-prefect) pad-2 :: testing/prefect-sandbox/testing-prefect βΉmain*βΊ
Β» cat run_python.py
β File: run_python.py
1 β from prefect import flow
2 β
3 β
4 β @flow
5 β def mini_flow(arg1: list[str]) -> str:
6 β print(arg1)
7 β return ",".join(arg1)
8 β
9 β
10 β if __name__ == "__main__":
11 β mini_flow.serve(name="mini-flow")
(bleeding-prefect) pad-2 :: testing/prefect-sandbox/testing-prefect βΉmain*βΊ
Β» python run_python.py
β Your flow 'mini-flow' is being served and polling for scheduled runs! β
β β
β To trigger a run for this flow, use the following command: β
β β
β $ prefect deployment run 'mini-flow/mini-flow' β
β β
β You can also run your flow via the Prefect UI:
β <https://app.prefect.cloud/account/xxx>
^C11:58:32.559 | INFO | prefect.runner - Pausing schedules for all deployments...
11:58:32.683 | INFO | prefect.runner - All deployment schedules have been paused!
(bleeding-prefect) pad-2 :: testing/prefect-sandbox/testing-prefect βΉmain*βΊ
Β» pip list | rg 'prefect|pydantic'
prefect 2.14.3
pydantic 2.4.2
pydantic_core 2.10.1
Nate
11/09/2023, 6:00 PMPeter Kim
11/09/2023, 6:01 PMPeter Kim
11/09/2023, 6:03 PMNate
11/09/2023, 6:22 PMNate
11/09/2023, 6:22 PMNate
11/09/2023, 6:23 PMPeter Kim
11/09/2023, 6:23 PMPeter Kim
11/09/2023, 6:25 PMNate
11/09/2023, 6:26 PMPeter Kim
11/09/2023, 6:26 PMPeter Kim
11/09/2023, 6:26 PM