{"record":{"id":"3a7d47e69c83c608","repo":"huggingface/transformers","slug":"key-key-not-found-in-sizedict","errorCode":null,"errorMessage":"Key {key} not found in SizeDict.","messagePattern":"Key (.+?) not found in SizeDict\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":1028,"sourceCode":"\n\n@dataclass()\nclass SizeDict:\n    \"\"\"\n    Hashable dictionary to store image size information.\n    \"\"\"\n\n    height: int | None = None\n    width: int | None = None\n    longest_edge: int | None = None\n    shortest_edge: int | None = None\n    max_height: int | None = None\n    max_width: int | None = None\n\n    def __getitem__(self, key):\n        if hasattr(self, key):\n            return getattr(self, key)\n        raise KeyError(f\"Key {key} not found in SizeDict.\")\n\n    def get(self, key, default=None):\n        if hasattr(self, key) and getattr(self, key) is not None:\n            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","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L1010-L1046","documentation":"Error \"Key {key} not found in SizeDict.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in SizeDict attribute/item access when the requested key does not exist.","commonSituations":"Accessing a misspelled or unsupported key such as size_dict['short_edge'] on a SizeDict.","solutions":["Access only keys present in the SizeDict (e.g. via `size_dict['height']` after checking).","Normalize the size input with `convert_to_size_dict` so required keys exist."],"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-15T17:31:12.345Z"}