prefect icon indicating copy to clipboard operation
prefect copied to clipboard

Filtering with OrionClient.read_logs does not work

Open mathijscarlu opened this issue 2 years ago • 2 comments

First check

  • [X] I added a descriptive title to this issue.
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the Prefect documentation for this issue.
  • [X] I checked that this issue is related to Prefect and not one of its dependencies.

Bug summary

When passing a LogFilter object to the OrionClient.read_logs function, it seems not to be taken into account.

Reproduction

  1. Install prefect
  2. Run at least 2 flows, so you can check if the id filter works.
  3. Run the following script:
import asyncio
from uuid import UUID
from prefect.orion.schemas.filters import LogFilter, LogFilterFlowRunId, LogFilterLevel
from prefect.client import OrionClient

ORION_URL = "https://orion.capture-vintecc.com/api"
FLOW_RUN_ID = UUID("2f9ca187-b057-4e2a-8f71-5c5121e8d9a8")

async def get_logs(id):
    async with OrionClient(ORION_URL) as client:
        filter = LogFilter(flow_run_id=LogFilterFlowRunId(any_=[id]), level=LogFilterLevel(ge_=200))
        logs = await client.read_logs(log_filter=filter, limit=100, offset=0)
        for log in logs:
            if log.flow_run_id != id:
                print("Wrong flow run id found.")
                break


if __name__ ==  '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(get_logs(FLOW_RUN_ID))

Error

OUTPUT: Wrong flow run id found.

Versions

Version:             2.4.0
API version:         0.8.0
Python version:      3.8.13
Git commit:          513639e8
Built:               Tue, Sep 13, 2022 2:15 PM
OS/Arch:             win32/AMD64
Profile:             default
Server type:         hosted

Additional context

No response

mathijscarlu avatar Sep 19 '22 14:09 mathijscarlu

Thanks for the well written issue! This is confusing since the UI uses this route to retrieve logs. Perhaps the Python client just isn't passing the filter through?

zanieb avatar Sep 19 '22 14:09 zanieb

While debugging again, I found the issue and a fix. I hope I made a pull request in the correct way, this would be my first contribution to an open source project 😄

mathijscarlu avatar Sep 19 '22 15:09 mathijscarlu