{"record":{"id":"65c14d6b8b9b87ed","repo":"microsoft/semantic-kernel","slug":"this-restapipayload-instance-is-frozen-and-canno","errorCode":null,"errorMessage":"This `RestApiPayload` instance is frozen and cannot be modified.","messagePattern":"This `RestApiPayload` instance is frozen and cannot be modified\\.","errorType":"exception","errorClass":"FunctionExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/openapi_plugin/models/rest_api_payload.py","lineNumber":37,"sourceCode":"        schema: str | None = None,\n    ):\n        \"\"\"Initialize the RestApiPayload.\"\"\"\n        self._media_type = media_type\n        self._properties = properties\n        self._description = description\n        self._schema = schema\n        self._is_frozen = False\n\n    def freeze(self):\n        \"\"\"Make the instance immutable and freeze properties.\"\"\"\n        self._is_frozen = True\n        for property in self._properties:\n            property.freeze()\n\n    def _throw_if_frozen(self):\n        \"\"\"Raise an exception if the object is frozen.\"\"\"\n        if self._is_frozen:\n            raise FunctionExecutionException(\"This `RestApiPayload` instance is frozen and cannot be modified.\")\n\n    @property\n    def media_type(self):\n        \"\"\"Get the media type of the payload.\"\"\"\n        return self._media_type\n\n    @media_type.setter\n    def media_type(self, value: str):\n        self._throw_if_frozen()\n        self._media_type = value\n\n    @property\n    def description(self):\n        \"\"\"Get the description of the payload.\"\"\"\n        return self._description\n\n    @description.setter\n    def description(self, value: str | None):","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_payload.py#L19-L55","documentation":"`RestApiPayload._throw_if_frozen` raises `FunctionExecutionException` if any setter is invoked after `freeze()` set `_is_frozen = True`. Because `freeze()` also calls `property.freeze()` on every nested property, the whole payload tree becomes immutable once an owning operation is frozen after REST-function registration.","triggerScenarios":"Setting `media_type` or any other payload property after the operation owning the payload has been frozen. The freeze cascade is triggered by `RestApiOperation.freeze()` (called at the end of `_create_rest_api_operation` registration in `create_rest_api_operations` / inside `create_functions_from_openapi`).","commonSituations":"Editing `operation.payload` (e.g. swapping the media type or rewriting properties) after the plugin was already added to the kernel; sharing a parsed operation between two kernel functions and mutating it for the second one; test code that post-processes parsed payloads.","solutions":["Edit the source OpenAPI spec and re-run `create_functions_from_openapi` so a fresh (unfrozen) payload is built.","Construct a new `RestApiPayload(...)` with the desired fields and assign it before registration.","Perform any payload mutation prior to the `operation.freeze()` call in the registration pipeline.","Avoid reusing a payload object across multiple registered operations."],"exampleFix":"// before\nkernel.add_openapi_plugin(...)\noperation.payload.media_type = \"application/xml\"  # raises 1481\n\n// after\nspec[\"paths\"][\"/x\"][\"post\"][\"requestBody\"][\"content\"] = {\"application/xml\": {...}}\nkernel.add_openapi_plugin_from_spec(spec, ...)","handlingStrategy":"validation","validationCode":"def assert_payload_mutable(payload) -> None:\n    if getattr(payload, \"_is_frozen\", False):\n        raise RuntimeError(\"RestApiPayload is frozen; reconstruct it instead.\")\n\nassert_payload_mutable(operation.payload)","typeGuard":"def is_unfrozen_payload(obj) -> bool:\n    return hasattr(obj, \"_is_frozen\") and not obj._is_frozen","tryCatchPattern":"from semantic_kernel.exceptions import FunctionExecutionException\n\ntry:\n    operation.payload.media_type = \"application/json\"\nexcept FunctionExecutionException as e:\n    if \"frozen\" in str(e):\n        # rebuild from spec instead\n        raise RuntimeError(\"Re-parse the spec to change payload media type\") from e\n    raise","preventionTips":["Edit the request body in the source spec, not the parsed payload.","Never share a parsed operation between two kernel functions.","Deep-copy parsed trees before mutating in tests.","Assert media types in the spec before registration."],"tags":["openapi-plugin","immutability","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}