PrefectFuture.get_state and sync called from an asynchronous context warning

Hello,

I have some prefect code that in very simplified way looks as follows,

from prefect import flow, task
import asyncio

@task
def task1(x: str):
    return x

@flow()
def flow_main():
    res = task1.submit("a")
    if res.get_state().is_failed():
        raise ValueError
    res.wait()

async def main():
    flow_main()

if __name__ == "__main__":
    asyncio.run(main())

This works, but raises the following warning,

prefect/utilities/asyncutils.py:287: UserWarning: `sync` called from an asynchronous context;
 you should `await` the async function directly instead.

My question how do I get rid of the warning in this case? The real code is more complex but essentially I need to check if a PrefectFuture state failed or not (and do some custom logic if it did). It looks like “sync” is called internally in get_state, but it’s not something I can control. The docstring of the sync function says,

Call an async function from a synchronous context. Block until completion.

If in an asynchronous context, we will run the code in a separate loop instead of
failing but a warning will be displayed since this is not recommended.

The code is run from an async context but none of the defined tasks and flows are async, and I would rather not make them async, unless there is no way around it?

Thanks you!

Using Prefect 2.16.18

I saw `PrefectFuture` method `get_state()` returns `coroutine` object - #2 by ZelterNN but I don’t think it answers my question.