{"record":{"id":"246b675b2f7ea6ef","repo":"langflow-ai/langflow","slug":"cannot-request-logs-before-and-after-the-timestamp","errorCode":null,"errorMessage":"Cannot request logs before and after the timestamp","messagePattern":"Cannot request logs before and after the timestamp","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"src/backend/base/langflow/api/log_router.py","lineNumber":92,"sourceCode":"\n@log_router.get(\"/logs\", dependencies=[Depends(get_current_active_superuser)])\nasync def logs(\n    lines_before: Annotated[int, Query(description=\"The number of logs before the timestamp or the last log\")] = 0,\n    lines_after: Annotated[int, Query(description=\"The number of logs after the timestamp\")] = 0,\n    timestamp: Annotated[int, Query(description=\"The timestamp to start getting logs from\")] = 0,\n):\n    \"\"\"Retrieve application logs with superuser authentication required.\n\n    SECURITY: Logs may contain sensitive information and require superuser authentication.\n    \"\"\"\n    global log_buffer  # noqa: PLW0602\n    if log_buffer.enabled() is False:\n        raise HTTPException(\n            status_code=HTTPStatus.NOT_IMPLEMENTED,\n            detail=\"Log retrieval is disabled\",\n        )\n    if lines_after > 0 and lines_before > 0:\n        raise HTTPException(\n            status_code=HTTPStatus.BAD_REQUEST,\n            detail=\"Cannot request logs before and after the timestamp\",\n        )\n    if timestamp <= 0:\n        if lines_after > 0:\n            raise HTTPException(\n                status_code=HTTPStatus.BAD_REQUEST,\n                detail=\"Timestamp is required when requesting logs after the timestamp\",\n            )\n        content = log_buffer.get_last_n(10) if lines_before <= 0 else log_buffer.get_last_n(lines_before)\n    elif lines_before > 0:\n        content = log_buffer.get_before_timestamp(timestamp=timestamp, lines=lines_before)\n    elif lines_after > 0:\n        content = log_buffer.get_after_timestamp(timestamp=timestamp, lines=lines_after)\n    else:\n        content = log_buffer.get_before_timestamp(timestamp=timestamp, lines=10)\n    return JSONResponse(content=content)\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/log_router.py#L74-L110","documentation":"HTTP 400 from GET /api/v1/logs when both lines_before and lines_after query parameters are > 0. The API only supports paging in one direction from a timestamp at a time; asking for both sides of the timestamp in one request is rejected.","triggerScenarios":"Calling /api/v1/logs?lines_before=10&lines_after=10 (optionally with timestamp) as superuser with the log buffer enabled.","commonSituations":"UI log viewers trying to fetch a context window around a timestamp in a single request; ported client code assuming a 'range' query API.","solutions":["Split into two requests: one with lines_before, one with lines_after","Fetch before and after pages separately and merge client-side","If you need a continuous window, request get_last_n semantics by omitting timestamp with lines_before only"],"exampleFix":"# before\nGET /api/v1/logs?timestamp=1700000000&lines_before=10&lines_after=10  # 400\n# after\nGET /api/v1/logs?timestamp=1700000000&lines_before=10\nGET /api/v1/logs?timestamp=1700000000&lines_after=10","handlingStrategy":"validation","validationCode":"const url = new URL('/api/v1/logs', base);\nif (linesBefore > 0) url.searchParams.set('lines_before', linesBefore);\nif (linesAfter > 0 && !linesBefore) { url.searchParams.set('lines_after', linesAfter); url.searchParams.set('timestamp', ts); }","typeGuard":null,"tryCatchPattern":"try { ... } catch (e) { if (e.response?.status === 400 && /before and after/.test(e.detail)) { return merge(await getBefore(ts), await getAfter(ts)); } throw e; }","preventionTips":["Never send lines_before and lines_after together","Build query params conditionally, defaulting omitted params to 0","Unit-test log-viewer queries against the param matrix"],"tags":["logging","http-400","query-params","api-usage"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}