Hi all I am having a weird bug with Block document...
# ask-community
m
Hi all I am having a weird bug with Block documents using a self hosted prefect server: I am able to connect to the client and everything is fine but for some reason this weird
ephemeral-client
url gets injected... what is going on/ what am I doing wrong? I set the configs and env vars
Copy code
17    raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__18prefect.exceptions.PrefectHTTPStatusError: Client error '404 Not Found' for url '<http://ephemeral-prefect/api/block_documents/782ccd86-fa13-40a6-8e89-278adb4aec24?include_secrets=true'19Response>: {'detail': 'Block document not found'}
j
hey, this means PREFECT_API_URL isn’t set on the client. So it’s not talking to your hosted server, it’s using the ephemeral api instead.
m
@Kol
k
@Jake Kaplan thank you for your speedy answer, this is what we have anticipated but we are explicitly setting it in an
__init__
function
m
Yea I felt like that may be the issue and I explicitly set this multiple times in 3 different ways @Jake Kaplan
Copy code
class MulticastPrefectOperator:

    def __init__(self, settings: MulticastInfraSettings = MulticastInfraSettings()):
        PREFECT_API_URL = "<https://dev.prefect.get-clarity.io/api>"
        os.environ["PREFECT_API_URL"] = PREFECT_API_URL
        os.system(f"prefect config set PREFECT_API_URL={PREFECT_API_URL}")

        self.settings = settings
        self.prefect_client: PrefectClient = PrefectClient(api="<https://dev.prefect.our-domain-foo.io/api>")
works in some places and for some reason its failing in others🤷
j
Normally you would set that in your profile.
prefect config set PREFECT_API_URL=...
or set as an env var on the machine so it gets picked up in the settings context
Instantiating an instance of the client with that url won't set it globally. There can be multiple instances of the client. Are you trying to use the client directly for something?
m
yep- want to query flow runs
j
I see. I would try looking at the docs I linked to set
PREFECT_API_URL
in the two ways I mentioned above, so it will be set for the entire context at the start of the process
then you should be able to do something like:
Copy code
from prefect import flow
from prefect.client.orchestration import get_client

@flow
async def my_flow():
    async with get_client() as client:
        await client.read_flow_runs(...)
safely