{"record":{"id":"558021604bb89a08","repo":"getredash/redash","slug":"script-not-found-in-script-directory","errorCode":null,"errorMessage":"Script '{}' not found in script directory","messagePattern":"Script '(.+?)' not found in script directory","errorType":"exception","errorClass":"IOError","httpStatus":null,"severity":"error","filePath":"redash/query_runner/script.py","lineNumber":11,"sourceCode":"import os\nimport subprocess\n\nfrom redash.query_runner import BaseQueryRunner, register\n\n\ndef query_to_script_path(path, query):\n    if path != \"*\":\n        script = os.path.join(path, query.split(\" \")[0])\n        if not os.path.exists(script):\n            raise IOError(\"Script '{}' not found in script directory\".format(query))\n\n        return os.path.join(path, query).split(\" \")\n\n    return query\n\n\ndef run_script(script, shell):\n    output = subprocess.check_output(script, shell=shell)\n    if output is None:\n        return None, \"Error reading output\"\n\n    output = output.strip()\n    if not output:\n        return None, \"Empty output from script\"\n\n    return output, None\n\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/script.py#L1-L29","documentation":"Raised by query_to_script_path (redash/query_runner/script.py:11) as IOError when the scripts directory is a fixed configured path (not '*') and the first token of the query does not correspond to an existing file under that directory. The runner maps the first whitespace-delimited word of the query to a script filename, so any name not present on disk fails here before execution.","triggerScenarios":"Running a Script data source query whose first word names a script that was renamed, deleted, never deployed, or contains a typo; also when the Redash server's configured scripts directory differs from where the script was placed.","commonSituations":"Scripts deployed to /opt/redash/scripts locally but the configured path points elsewhere; script renamed without updating saved queries; leading whitespace/formatting making the first token something unexpected.","solutions":["List the configured scripts directory on the Redash server and confirm the exact filename of the first query token (case-sensitive)","Fix the saved query's first word to match the script filename, or restore/redeploy the missing script","Verify the Scripts directory setting on the data source matches where scripts actually live"],"exampleFix":"# before\n# query: my_scritp.py arg1   (typo)\n# after\n# query: my_script.py arg1","handlingStrategy":"validation","validationCode":"import os\nfirst = query.split(' ')[0]\nscript_path = os.path.join(scripts_dir, first)\nif not os.path.exists(script_path):\n    return None, \"Script '{}' not found in {}\".format(first, scripts_dir)","typeGuard":null,"tryCatchPattern":"try:\n    run_query(q, user)\nexcept IOError as e:\n    return error_response(404, str(e))","preventionTips":["Pin the scripts directory in config management and deploy scripts there atomically","Name saved queries after exact script filenames; add a CI check that referenced scripts exist","Expose a listing endpoint or README of available scripts for query authors"],"tags":["script-runner","redash","file-not-found","io"],"backgroundTag":"file-not-found","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}