{"record":{"id":"cec63f2c3702ef5d","repo":"keras-team/keras","slug":"in-layer-self-class-name-you-forgot-t","errorCode":null,"errorMessage":"In layer '{self.__class__.__name__}', you forgot to call `super().__init__()` as the first statement in the `__init__()` method. Go add it!","messagePattern":"In layer '(.+?)', you forgot to call `super\\(\\)\\.__init__\\(\\)` as the first statement in the `__init__\\(\\)` method\\. Go add it!","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"keras/src/layers/layer.py","lineNumber":1694,"sourceCode":"        super().__setattr__(name, value)\n\n    def __delattr__(self, name):\n        obj = getattr(self, name)\n        if isinstance(obj, backend.Variable):\n            import gc\n\n            # It will take a short amount of time for the corresponding buffer\n            # to be actually removed from the device.\n            # https://stackoverflow.com/a/74631949\n            self._untrack_variable(obj)\n            super().__delattr__(name)\n            gc.collect()\n        else:\n            super().__delattr__(name)\n\n    def _check_super_called(self):\n        if getattr(self, \"_lock\", True):\n            raise RuntimeError(\n                f\"In layer '{self.__class__.__name__}', you forgot to call \"\n                \"`super().__init__()` as the first statement \"\n                \"in the `__init__()` method. Go add it!\"\n            )\n\n    def _assert_input_compatibility(self, arg_0):\n        if self.input_spec:\n            try:\n                input_spec.assert_input_compatibility(\n                    self.input_spec, arg_0, layer_name=self.name\n                )\n            except SystemError:\n                if backend.backend() == \"torch\":\n                    # TODO: The torch backend failed the ONNX CI with the error:\n                    # SystemError: <method '__int__' of 'torch._C.TensorBase'\n                    # objects> returned a result with an exception set\n                    # As a workaround, we are skipping this for now.\n                    pass","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L1676-L1712","documentation":"Keras 3's Layer relies on attributes set in Layer.__init__ (like _lock). If a subclass __init__ never calls super().__init__(), the _lock attribute lookup defaults to True and this RuntimeError is raised on the first API use (build, add_weight, __call__, stateless_call, get_config).","triggerScenarios":"Custom layer whose __init__ sets attributes but omits super().__init__(**kwargs); copied PyTorch-style classes; multiple inheritance where the MRO skips Layer.__init__.","commonSituations":"Writing first custom layers; porting PyTorch modules; refactoring __init__ and accidentally deleting the super call.","solutions":["Add super().__init__(**kwargs) as the first statement of the subclass __init__","In multi-inheritance, ensure Layer appears in the MRO and cooperative super() is used"],"exampleFix":"# before\nclass MyLayer(keras.layers.Layer):\n    def __init__(self, units):\n        self.units = units\n# after\nclass MyLayer(keras.layers.Layer):\n    def __init__(self, units, **kwargs):\n        super().__init__(**kwargs)\n        self.units = units","handlingStrategy":"validation","validationCode":"class MyLayer(keras.layers.Layer):\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)  # mandatory\n        ...","typeGuard":null,"tryCatchPattern":"try:\n    layer(x)\nexcept RuntimeError as e:\n    if 'super().__init__()' in str(e):\n        fix_init(); layer(x)","preventionTips":["Always start custom layer __init__ with super().__init__(**kwargs)","Use cooperative super() in multi-inheritance layer hierarchies"],"tags":["keras","custom-layers","init","subclassing"],"backgroundTag":"missing-super-init","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}