Thread
#prefect-server
    y

    Yash

    8 months ago
    Hi everyone, is there any way to get flow run name inside flow while executing or any way to pass flow run name as a parameter for scheduled flow?
    Kevin Kho

    Kevin Kho

    8 months ago
    You can use the
    RenameFlowRun
    task or you can get it from the
    context
    with
    prefect.context.flow_run_name
    y

    Yash

    8 months ago
    Thanks @Kevin Kho !!!
    import prefect
    
    def create_test_group(group_name):
        with Flow(name=group_name) as flow:
    
            flow_run_id = prefect.context.flow_run_id
            flow_run_name = prefect.context.flow_run_name
            run_config_dir, run_report_dir, num_testcases = create_config(group_name, flow_run_id)
            start_orchestration(run_config_dir, run_report_dir, num_testcases, flow_run_name, flow_run_id)
    
        flow.register()
    
        return flow
    Hi, @Kevin Kho and @Anna Geller. This is the code that I wrote but when I ran it, I'm getting a error like mentioned below. I'm using local server and agent. Thanks!!!
    flow_run_id = prefect.context.flow_run_id
    AttributeError: 'Context' object has no attribute 'flow_run_id'
    Kevin Kho

    Kevin Kho

    8 months ago
    Stuff in the Flow block is not deferred. You need to use the
    context
    inside tasks so that they are evaluated during the Flow run. If you do it during the Flow block, it is evaluated during registration time where it doesn’t exist yet.
    y

    Yash

    8 months ago
    oh ok, thanks @Kevin Kho.
    Hi the issue got resolved. But I'm getting a error while registering the flow flow.register(project_name='Test'). I have already created the project called Test.
    ERROR:uvicorn.error:Exception in ASGI application
    Traceback (most recent call last):
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
        result = await app(self.scope, self.receive, self.send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
        return await <http://self.app|self.app>(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\fastapi\applications.py", line 208, in __call__
        await super().__call__(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
        raise exc from None
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
        await <http://self.app|self.app>(scope, receive, _send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\exceptions.py", line 82, in __call__
        raise exc from None
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\exceptions.py", line 71, in __call__
        await <http://self.app|self.app>(scope, receive, sender)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\routing.py", line 580, in __call__
        await route.handle(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\routing.py", line 390, in handle
        await <http://self.app|self.app>(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\fastapi\applications.py", line 208, in __call__
        await super().__call__(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
        raise exc from None
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
        await <http://self.app|self.app>(scope, receive, _send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\exceptions.py", line 82, in __call__
        raise exc from None
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\exceptions.py", line 71, in __call__
        await <http://self.app|self.app>(scope, receive, sender)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\routing.py", line 580, in __call__
        await route.handle(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\routing.py", line 241, in handle
        await <http://self.app|self.app>(scope, receive, send)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\starlette\routing.py", line 52, in app
        response = await func(request)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\fastapi\routing.py", line 219, in app
        raw_response = await run_endpoint_function(
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\fastapi\routing.py", line 152, in run_endpoint_function
        return await dependant.call(**values)
      File ".\prefect_layer\prefect_interaction.py", line 28, in create_test_group
        flow.register(project_name='Test')
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\prefect\core\flow.py", line 1727, in register
        registered_flow = client.register(
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\prefect\client\client.py", line 1133, in register
        serialized_flow = flow.serialize(build=build)  # type: Any
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\prefect\core\flow.py", line 1489, in serialize
        self.storage.add_flow(self)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\prefect\storage\local.py", line 143, in add_flow
        f.write(flow_to_bytes_pickle(flow))
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\prefect\utilities\storage.py", line 177, in flow_to_bytes_pickle
        cloudpickle.dumps(flow, protocol=4), newline=False
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\cloudpickle\cloudpickle_fast.py", line 73, in dumps
        cp.dump(obj)
      File "D:\Exafluence\Test_Suit\venv\lib\site-packages\cloudpickle\cloudpickle_fast.py", line 602, in dump
        return Pickler.dump(self, obj)
    _pickle.PicklingError: args[0] from __newobj__ args has the wrong class
    Anna Geller

    Anna Geller

    8 months ago
    looks like something in your flow definition can’t be pickled. Can you show your flow definition? you can share in DM for privacy. Usually if you have some DB connections or HTTP client as return values of a task, it causes similar issues, so it’s better to avoid that
    y

    Yash

    8 months ago
    Thanks @Anna Geller, yes its a flask current user method that caused error. now its resolved.