{"record":{"id":"6bb6ca401b913dcb","repo":"pallets/flask","slug":"failed-to-parse-arguments-as-literal-values-app","errorCode":null,"errorMessage":"Failed to parse arguments as literal values: {app_name!r}.","messagePattern":"Failed to parse arguments as literal values: (.+?)\\.","errorType":"exception","errorClass":"NoAppException","httpStatus":null,"severity":"error","filePath":"src/flask/cli.py","lineNumber":159,"sourceCode":"        if not isinstance(expr.func, ast.Name):\n            raise NoAppException(\n                f\"Function reference must be a simple name: {app_name!r}.\"\n            )\n\n        name = expr.func.id\n\n        # Parse the positional and keyword arguments as literals.\n        try:\n            args = [ast.literal_eval(arg) for arg in expr.args]\n            kwargs = {\n                kw.arg: ast.literal_eval(kw.value)\n                for kw in expr.keywords\n                if kw.arg is not None\n            }\n        except ValueError:\n            # literal_eval gives cryptic error messages, show a generic\n            # message with the full expression instead.\n            raise NoAppException(\n                f\"Failed to parse arguments as literal values: {app_name!r}.\"\n            ) from None\n    else:\n        raise NoAppException(\n            f\"Failed to parse {app_name!r} as an attribute name or function call.\"\n        )\n\n    try:\n        attr = getattr(module, name)\n    except AttributeError as e:\n        raise NoAppException(\n            f\"Failed to find attribute {name!r} in {module.__name__!r}.\"\n        ) from e\n\n    # If the attribute is a function, call it with any args and kwargs\n    # to get the real application.\n    if inspect.isfunction(attr):\n        try:","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/cli.py#L141-L177","documentation":"Raised by find_app_by_string when the call expression parses but its positional or keyword arguments are not Python literals (ast.literal_eval raises ValueError). Only literal values can be supplied to a factory via FLASK_APP.","triggerScenarios":"export FLASK_APP='module:create_app(os.environ[\"CONFIG\"])' — arguments reference names/calls, not literals. Only values like strings, numbers, tuples are allowed.","commonSituations":"Trying to inject runtime/env values directly into the FLASK_APP factory call; using variable names instead of literal strings.","solutions":["Pass only literal arguments: export FLASK_APP='module:create_app(\"production\")'.","Read environment variables inside the factory instead of passing them via FLASK_APP.","Use a wrapper function that computes args and then calls the factory."],"exampleFix":"// before\n# export FLASK_APP='module:create_app(os.environ[\"CFG\"])'  # raises\n// after\n# export FLASK_APP='module:create_app(\"production\")'\n# and read os.environ inside the factory","handlingStrategy":"validation","validationCode":"import ast\nexpr = ast.parse(app_name.strip(), mode='eval').body\nfor arg in getattr(expr, 'args', []):\n    ast.literal_eval(arg)\nfor kw in getattr(expr, 'keywords', []):\n    ast.literal_eval(kw.value)","typeGuard":"import ast\ndef args_are_literals(s) -> bool:\n    try:\n        expr = ast.parse(s.strip(), mode='eval').body\n        for arg in getattr(expr, 'args', []):\n            ast.literal_eval(arg)\n        return True\n    except (ValueError, SyntaxError):\n        return False","tryCatchPattern":"try:\n    app = find_app_by_string(module, app_name)\nexcept NoAppException:\n    # replace non-literal args with literal strings\n    raise","preventionTips":["Pass only literal values (strings, numbers, tuples) via FLASK_APP.","Read environment variables inside the factory.","Use a wrapper factory for dynamic args."],"tags":["cli","flask-app-env","parsing"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}