{"record":{"id":"b98f2493a6ef9167","repo":"Zie619/n8n-workflows","slug":"workflow-not-found-in-database","errorCode":null,"errorMessage":"Workflow not found in database","messagePattern":"Workflow not found in database","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"api_server.py","lineNumber":327,"sourceCode":"async def get_workflow_detail(filename: str, request: Request):\n    \"\"\"Get detailed workflow information including raw JSON.\"\"\"\n    try:\n        # Security: Validate filename to prevent path traversal\n        if not validate_filename(filename):\n            print(f\"Security: Blocked path traversal attempt for filename: {filename}\")\n            raise HTTPException(status_code=400, detail=\"Invalid filename format\")\n\n        # Security: Rate limiting\n        client_ip = request.client.host if request.client else \"unknown\"\n        if not check_rate_limit(client_ip):\n            raise HTTPException(\n                status_code=429, detail=\"Rate limit exceeded. Please try again later.\"\n            )\n\n        # Get workflow metadata from database\n        workflows, _ = db.search_workflows(f'filename:\"{filename}\"', limit=1)\n        if not workflows:\n            raise HTTPException(\n                status_code=404, detail=\"Workflow not found in database\"\n            )\n\n        workflow_meta = workflows[0]\n\n        # Load raw JSON from file with security checks\n        workflows_path = Path(\"workflows\").resolve()\n\n        # Find the file safely\n        matching_file = None\n        for subdir in workflows_path.iterdir():\n            if subdir.is_dir():\n                target_file = subdir / filename\n                if target_file.exists() and target_file.is_file():\n                    # Verify the file is actually within workflows directory\n                    try:\n                        target_file.resolve().relative_to(workflows_path)\n                        matching_file = target_file","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/api_server.py#L309-L345","documentation":"A 404 from GET /api/workflows/{filename} raised when the filename passes validation and rate limiting but db.search_workflows(f'filename:\"{filename}\"', limit=1) returns no rows. The workflow lookup happens against the SQLite index, not the filesystem, so the DB has never heard of this file even if it exists on disk.","triggerScenarios":"Requesting a workflow JSON that was added to workflows/ after the last indexing run; a filename whose exact string (case, spacing, .json suffix) differs from the indexed value; the DB being rebuilt from a different directory snapshot; a filename containing a double quote breaking the quoted query.","commonSituations":"Git-pulling new workflow files without reindexing; renaming files on disk; querying with a name copied from the filesystem listing rather than from the API's own search results.","solutions":["Trigger a reindex (POST /api/reindex with a valid ADMIN_TOKEN) so newly added files enter the database.","Take the exact filename value from GET /api/workflows results instead of constructing it by hand.","Verify the file lives inside a subdirectory of workflows/ — the indexer and filesystem search both expect that layout.","If reindexing does not pick the file up, check the file is valid JSON and matches the indexer's inclusion rules."],"exampleFix":"# before\nworkflows, _ = db.search_workflows(f'filename:\"{filename}\"', limit=1)\n\n# after (parameterized exact-match lookup, quote-safe)\nworkflows, _ = db.search_workflows(f'filename:\"{filename.replace(chr(34), \"\")}\"', limit=1)","handlingStrategy":"validation","validationCode":"import urllib.request, json\n\ndef filename_in_index(base, name):\n    with urllib.request.urlopen(f'{base}/api/workflows?q={name}', timeout=5) as r:\n        items = json.load(r).get('workflows', [])\n    return any(w.get('filename') == name for w in items)","typeGuard":null,"tryCatchPattern":"try:\n    meta = client.get(f'/api/workflows/{name}').json()\nexcept HTTPError as e:\n    if e.response.status_code == 404 and 'not found in database' in e.response.text:\n        client.post(f'/api/reindex?admin_token={TOKEN}')  # then retry","preventionTips":["Reindex on every deploy that adds/removes workflow files.","Use filenames exactly as the listing endpoint returns them.","Treat a 404 'not found in database' as an index-staleness signal, not a user error."],"tags":["fastapi","database","indexing","http-404"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}