{"record":{"id":"892b659df69229e8","repo":"keras-team/keras","slug":"the-shape-of-the-target-variable-and-the-shape-of","errorCode":null,"errorMessage":"The shape of the target variable and the shape of the target value in `variable.assign(value)` must match. variable.shape={self.shape}, Received: value.shape={value.shape}. Target variable: {self}","messagePattern":"The shape of the target variable and the shape of the target value in `variable\\.assign\\(value\\)` must match\\. variable\\.shape=(.+?), Received: value\\.shape=(.+?)\\. Target variable: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":285,"sourceCode":"        if in_stateless_scope():\n            scope = get_stateless_scope()\n            value = scope.get_current_value(self)\n            if value is not None:\n                return self._maybe_autocast(value)\n        if self._value is None:\n            # Uninitialized variable. Return a placeholder.\n            # This is fine because it's only ever used\n            # in during shape inference / graph tracing\n            # (anything else would be a bug, to be fixed.)\n            return self._maybe_autocast(\n                self._initializer(self._shape, dtype=self._dtype)\n            )\n        return self._maybe_autocast(self._value)\n\n    def assign(self, value):\n        value = self._convert_to_tensor(value, dtype=self._dtype)\n        if not shape_equal(value.shape, self.shape):\n            raise ValueError(\n                \"The shape of the target variable and \"\n                \"the shape of the target value in \"\n                \"`variable.assign(value)` must match. \"\n                f\"variable.shape={self.shape}, \"\n                f\"Received: value.shape={value.shape}. \"\n                f\"Target variable: {self}\"\n            )\n        if in_stateless_scope():\n            scope = get_stateless_scope()\n            scope.add_update((self, value))\n        else:\n            self._direct_assign(value)\n        return value\n\n    def assign_add(self, value):\n        return self.assign(self + value)\n\n    def assign_sub(self, value):","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L267-L303","documentation":"Error \"The shape of the target variable and the shape of the target value in `variable.assign(value)` must match. variable.shape={self.shape}, Received: value.shape={value.shape}. Target variable: {self}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:285 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}