{"record":{"id":"e9ade24e6e397100","repo":"ruvnet/RuView","slug":"query-range-cannot-exceed-7-days","errorCode":null,"errorMessage":"Query range cannot exceed 7 days","messagePattern":"Query range cannot exceed 7 days","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"archive/v1/src/api/routers/pose.py","lineNumber":257,"sourceCode":"@router.post(\"/historical\")\nasync def get_historical_data(\n    request: HistoricalDataRequest,\n    pose_service: PoseService = Depends(get_pose_service),\n    current_user: Dict = Depends(require_auth)\n):\n    \"\"\"Get historical pose estimation data.\"\"\"\n    try:\n        # Validate time range\n        if request.end_time <= request.start_time:\n            raise HTTPException(\n                status_code=400,\n                detail=\"End time must be after start time\"\n            )\n        \n        # Limit query range to prevent excessive data\n        max_range = timedelta(days=7)\n        if request.end_time - request.start_time > max_range:\n            raise HTTPException(\n                status_code=400,\n                detail=\"Query range cannot exceed 7 days\"\n            )\n        \n        data = await pose_service.get_historical_data(\n            start_time=request.start_time,\n            end_time=request.end_time,\n            zone_ids=request.zone_ids,\n            aggregation_interval=request.aggregation_interval,\n            include_raw_data=request.include_raw_data\n        )\n        \n        return {\n            \"query\": {\n                \"start_time\": request.start_time,\n                \"end_time\": request.end_time,\n                \"zone_ids\": request.zone_ids,\n                \"aggregation_interval\": request.aggregation_interval","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/api/routers/pose.py#L239-L275","documentation":"HTTP 400 from POST /pose/historical when end_time - start_time exceeds 7 days (max_range = timedelta(days=7)). The cap limits how much data a single query can aggregate. Combined with the ordering check, any accepted range is a positive span of at most 7 days.","triggerScenarios":"POST /pose/historical requesting a 30-day window (end - start > 7 days), e.g. a monthly dashboard default or a full-history export attempt.","commonSituations":"Dashboards defaulting to 30/90-day windows; export scripts trying to pull all history in one call.","solutions":["Split the request into consecutive windows of at most 7 days and aggregate client-side (see exampleFix)","Keep default visible windows to 7 days or less","If you operate the server and genuinely need longer ranges, raise max_range knowing larger queries cost more"],"exampleFix":"# before\nwindows = [(now - timedelta(days=30), now)]\n\n# after\nwindows = []\ncur = now - timedelta(days=30)\nwhile cur < now:\n    windows.append((cur, min(cur + timedelta(days=7), now)))\n    cur += timedelta(days=7)","handlingStrategy":"validation","validationCode":"from datetime import timedelta\n\ndef chunk_range(start, end, max_days=7):\n    windows = []\n    cur = start\n    while cur < end:\n        nxt = min(cur + timedelta(days=max_days), end)\n        windows.append((cur, nxt))\n        cur = nxt\n    return windows","typeGuard":null,"tryCatchPattern":"resp = await client.post('/pose/historical', json=body)\nif resp.status_code == 400 and 'cannot exceed' in resp.json().get('detail', ''):\n    results = [await fetch_window(s, e) for s, e in chunk_range(start, end)]\nelse:\n    resp.raise_for_status()","preventionTips":["Cap default dashboard windows at 7 days","Chunk exports client-side instead of requesting full history","Encode the 7-day limit as a client constant next to the range picker"],"tags":["python","fastapi","validation","http-400","time-range","historical"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}