Thread
#prefect-community
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    Hi everybody, I'm working on a flow which should register another flow. And while flow.run() works perfectly fine for me, the running on the Cloud gives an error described in the picture. I've dived into this issue and realized that it does register another flow but outputs an error printing the success message))). So I tried changing print(msg) -> print(msg.encode('utf-8')) in the line 979 of the prefect/client/client.py and it helped me to fix this issue. Please consider adding this changing to the later versions of Prefect. Thank you in advance
    Anna Geller

    Anna Geller

    6 months ago
    Can you share the code that registers other flows? The output looks like you are using CLI rather than
    prefect.Client
    Also, can you explain the use case a bit more? Perhaps there is some better way of approaching this. Are you trying to build some CI/CD pipeline using this approach?
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    Sorry, but I can't share the code. The purpose of this flow is to be able to register new flows without having direct access to the local agent. It works by the following scheme: the task calls a function from another file (in order to avoid reregistration of this flow) and the function calls another_flow.register(some_project)
    To be honest I don't know the difference between CLI and prefect.Client so my approach can be wrong
    Anna Geller

    Anna Geller

    6 months ago
    Do you use some Cyrillic characters in your flow name?
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    No
    Anna Geller

    Anna Geller

    6 months ago
    I plan to create a Github issue but want to gather more information first. Can you explain your use case?
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    What info should I add (because I can't share any sensitive information)?
    Or should I gather all the info in 1 message?
    Anna Geller

    Anna Geller

    6 months ago
    That would be great, you can redact any sensitive information. But e.g. it's useful to know WHERE do you call
    flow.register()
    because doing that within a Flow content may lead to unexpected results
    I can imagine sth like this should work, but it also depends on the Storage of your flows
    from prefect import Client
    from prefect import Flow, task
    
    
    @task(log_stdout=True)
    def register_other_flow():
        from yourmodule import your_flow_object
        Client().register(flow=your_flow_object, project_name="yourproject")
    
    
    with Flow("xxx") as flow:
        register_other_flow()
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    I see. I think it's within Flow context: not directly but the function which calls flow.register() is within the Flow context
    Anna Geller

    Anna Geller

    6 months ago
    but doing this is discouraged since in the Flow block you should only be calling your tasks:
    with Flow("xxx") as flow:
        your_flow_object.register("xxx")
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    It's more closer to this main_file.py
    from prefect import Flow, task
    
    
    @task(log_stdout=True)
    def register_other_flow():
        from yourmodule import run
        run()
    
    
    with Flow("xxx") as flow:
        register_other_flow()
    yourmodule.py
    def run():
        # here we conduct the registration
        flow.register()
    Anna Geller

    Anna Geller

    6 months ago
    I see. Can you try this and see if you get the same error?
    from prefect import Client
    from prefect import Flow, task
    
    
    @task(log_stdout=True)
    def register_other_flow():
        from yourmodule import your_flow_object
        Client().register(flow=your_flow_object, project_name="yourproject")
    
    
    with Flow("xxx") as flow:
        register_other_flow()
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    Ok.
    Anna Geller

    Anna Geller

    6 months ago
    in theory, it's calling the same register method, but dunno, could matter somehow 😄 I promise I'll open an issue if this doesn't work
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    Is Client.register() a static method? Can Client().register(...) also work?
    Anna Geller

    Anna Geller

    6 months ago
    sorry, my mistake, it must be Client()
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    Client().register(...) also fails. What should I specify to make it work?
    Anna Geller

    Anna Geller

    6 months ago
    thanks for trying that. Let me open an issue then 🙂 @Marvin open "Add UTF-8 encoding to the registration message"
    Marvin

    Marvin

    6 months ago
    Андрій Демиденко

    Андрій Демиденко

    6 months ago
    @Anna Geller Thank you very much
    Anna Geller

    Anna Geller

    6 months ago
    @Андрій Демиденко I was trying to reproduce your issue and I couldn't. I added a comment on the issue and closed it. All strings in Python 3+ are UTF-8 encoded already and the change you suggested would convert those to bytes which wouldn't make any difference in fixing your issue. Happy to help if you are still having issues with this. Generally speaking, it's recommended (and much easier!) to register flows from the CLI. Have you tried that? This way you could register multiple flows at once without having to register flows from other flows. E.g.:
    prefect register --project yourproject -p /path/to/multiple/flows/
    this way you can register both at once with no extra work