{"record":{"id":"606af334b96a8fac","repo":"getredash/redash","slug":"is-not-supported-inplace-variable","errorCode":null,"errorMessage":"'{} is not supported inplace variable","messagePattern":"'(.+?) is not supported inplace variable","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/python.py","lineNumber":177,"sourceCode":"    def custom_write(obj):\n        \"\"\"\n        Custom hooks which controls the way objects/lists/tuples/dicts behave in\n        RestrictedPython\n        \"\"\"\n        return full_write_guard(obj)\n\n    @staticmethod\n    def custom_get_item(obj, key):\n        return obj[key]\n\n    @staticmethod\n    def custom_get_iter(obj):\n        return iter(obj)\n\n    @staticmethod\n    def custom_inplacevar(op, x, y):\n        if op not in IOPERATOR_TO_STR.values():\n            raise Exception(\"'{} is not supported inplace variable'\".format(op))\n        glb = {\"x\": x, \"y\": y}\n        exec(\"x\" + op + \"y\", glb)\n        return glb[\"x\"]\n\n    @staticmethod\n    def add_result_column(result, column_name, friendly_name, column_type):\n        \"\"\"Helper function to add columns inside a Python script running in Redash in an easier way\n\n        Parameters:\n        :result dict: The result dict\n        :column_name string: Name of the column, which should be consisted of lowercase latin letters or underscore.\n        :friendly_name string: Name of the column for display\n        :column_type string: Type of the column. Check supported data types for details.\n        \"\"\"\n        if column_type not in SUPPORTED_COLUMN_TYPES:\n            raise Exception(\"'{0}' is not a supported column type\".format(column_type))\n\n        if \"columns\" not in result:","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/python.py#L159-L195","documentation":"RestrictedPython replaces augmented assignments (+=, -=, etc.) with calls to custom_inplacevar(). This Python runner hook only accepts operator strings present in its IOPERATOR_TO_STR mapping and performs the operation via exec. An unrecognized operator string (custom opcodes, unusual operators, or a mismatched RestrictedPython version whose generated op string differs) raises this Exception. Note the message itself has a stray quote: \"'{} is not supported inplace variable'\".","triggerScenarios":"Executing a Python query with an augmented assignment whose operator token isn't in IOPERATOR_TO_STR — most commonly after upgrading RestrictedPython where the operator encoding changed, producing unknown op strings for ordinary code like x += 1.","commonSituations":"RestrictedPython version drift between the pinned version the runner was built for and an installed newer/older one; rarely, exotic operators (matrix @=) not in the mapping.","solutions":["Pin RestrictedPython to the version required by your Redash release (check requirements.txt) e.g. pip install RestrictedPython==<pinned>","If you maintain the codebase, extend IOPERATOR_TO_STR with the missing operator mapping","As a query author, replace augmented assignment with explicit form: x = x + y instead of x += y"],"exampleFix":"# before\nx += 1\n# after\nx = x + 1","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    execute_python_query(code)\nexcept Exception as e:\n    if 'not supported inplace variable' in str(e):\n        code = rewrite_augmented_assignments(code)  # x += 1 -> x = x + 1\n        execute_python_query(code)","preventionTips":["Pin RestrictedPython to the version in requirements.txt","In shared query templates avoid augmented assignment","Extend IOPERATOR_TO_STR if you control the runner"],"tags":["redash","python-runner","restrictedpython","inplace-operators","version-mismatch"],"backgroundTag":"restrictedpython-inplacevar-unsupported","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}