{"record":{"id":"fa56a597ea331ba2","repo":"huggingface/transformers","slug":"key-key-is-not-a-valid-field-of-sizedict","errorCode":null,"errorMessage":"Key {key} is not a valid field of SizeDict.","messagePattern":"Key (.+?) is not a valid field of SizeDict\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":1050,"sourceCode":"            return getattr(self, key)\n        return default\n\n    def __iter__(self):\n        # Yield only non-None (key, value) pairs so dict(self) excludes missing values.\n        for f in fields(self):\n            val = getattr(self, f.name)\n            if val is not None:\n                yield f.name, val\n\n    def __hash__(self):\n        return hash((self.height, self.width, self.longest_edge, self.shortest_edge, self.max_height, self.max_width))\n\n    def __contains__(self, key):\n        return hasattr(self, key) and getattr(self, key) is not None\n\n    def __setitem__(self, key, value):\n        if not hasattr(self, key):\n            raise KeyError(f\"Key {key} is not a valid field of SizeDict.\")\n        object.__setattr__(self, key, value)\n\n    def __eq__(self, other):\n        if isinstance(other, dict):\n            return dict(self) == other\n        if isinstance(other, SizeDict):\n            return tuple(getattr(self, f.name) for f in fields(self)) == tuple(\n                getattr(other, f.name) for f in fields(self)\n            )\n        return NotImplemented\n\n    def __or__(self, other) -> \"SizeDict\":\n        if isinstance(other, dict | SizeDict):\n            merged = dict(self)\n            merged.update(dict(other))\n            return SizeDict(**merged)\n        return NotImplemented\n","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L1032-L1068","documentation":"Error \"Key {key} is not a valid field of SizeDict.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in SizeDict assignment when attempting to set a key that is not a declared field.","commonSituations":"Assigning arbitrary attributes to a SizeDict instead of its allowed size-related fields.","solutions":["Set only valid SizeDict fields such as 'height', 'width', 'shortest_edge', 'longest_edge', 'max_height', 'max_width'."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}