Hi everyone, I got a deployment and running into a...
# prefect-getting-started
a
Hi everyone, I got a deployment and running into a issue my code:
Copy code
import asyncio
from prefect import flow
from prefect.logging import get_logger

from src.db.mongodb_connection import (
    mongodb_fintech_conn,
    mongodb_staging_conn,
)
from src.utils.http_client import WifeedAPIClient, JsonFetcher
from src.workflows.wifeed_data_tasks import DataTask


class DataPipeline:
    def __init__(self):
       self.logger = get_logger()
       self.conn = mongodb_staging_conn
       self.client = WifeedAPIClient(json_file="json/wifeed_urls.json")
       self.fetcher = JsonFetcher(self.client)
       self.data_task = DataTask(self.client, self.fetcher)

    @flow
    async def run_staging(self, loaidn: str="", san: str=""):
       await self.data_task.fetch_raw_stock_list(self.conn, loaidn, san)


if __name__ == "__main__":
    pipeline = DataPipeline()
    pipeline.run_staging.deploy(
       name="my-deployment",
       work_pool_name="docker-wp",
       image="my-docker-image:dev",
       push=False
    )
when I'm run:
prefect deployment run 'run-staging/my-deployment'
it say:
Error creating flow run: Validation failed. Failure reason: 'self' is a required property
The worker is docker type. How should I fix this? thanks you
n
hi @An Vu Trong - the issue occurs because
run_staging
expects
self
to be passed, so when the run is created, the
parameters
do not contain a value for
self
we may want to support this at some point, but I would recommend changing your code to make
run_staging
a normal function (not a method on a class) • pass
DataPipeline
into
run_staging
• or instantiate
DataPipeline
within
run_staging
a
Thanks you Nate.
Maybe it is best that our Prefect document will have this. Or in case am I missing something 😅, sorry
n
generally speaking I recommend defining tasks and flows as pure functions, but we recently added support for them as methods - there are likely some edgecases, especially when your deployment entrypoint is not a pure function (i.e. not a method on a class) we could definitely add more docs on this though in the future, feel free to open an issue to that effect
a
yes, thanks you, that's my thought