{"record":{"id":"ce50328e8ef3dffb","repo":"apache/beam","slug":"dict-type-constraint-violated-all-passed-instances-must-be","errorCode":null,"errorMessage":"Dict type-constraint violated. All passed instances must be of type dict. %s is of type %s.","messagePattern":"Dict type-constraint violated\\. All passed instances must be of type dict\\. (.+?) is of type (.+?)\\.","errorType":"exception","errorClass":"CompositeTypeHintError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":909,"sourceCode":"                repr(self),\n                incorrect_type[:-1],\n                incorrect_type,\n                repr(hinted_type),\n                inner_error_message))\n      else:\n        raise CompositeTypeHintError(\n            '%s hint %s-type constraint violated. All %s should be of '\n            'type %s. Instead, %s is of type %s.' % (\n                repr(self),\n                incorrect_type[:-1],\n                incorrect_type,\n                repr(hinted_type),\n                incorrect_instance,\n                incorrect_instance.__class__.__name__))\n\n    def type_check(self, dict_instance):\n      if not isinstance(dict_instance, dict):\n        raise CompositeTypeHintError(\n            'Dict type-constraint violated. All passed instances must be of '\n            'type dict. %s is of type %s.' %\n            (dict_instance, dict_instance.__class__.__name__))\n\n      for key, value in dict_instance.items():\n        try:\n          check_constraint(self.key_type, key)\n        except CompositeTypeHintError as e:\n          self._raise_hint_exception_or_inner_exception(True, key, str(e))\n        except SimpleTypeHintError:\n          self._raise_hint_exception_or_inner_exception(True, key)\n\n        try:\n          check_constraint(self.value_type, value)\n        except CompositeTypeHintError as e:\n          self._raise_hint_exception_or_inner_exception(False, value, str(e))\n        except SimpleTypeHintError:\n          self._raise_hint_exception_or_inner_exception(False, value)","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L891-L927","documentation":"Runtime check in DictConstraint.type_check: a value passed under a Dict[K, V] typehint is not a dict at all (its actual type is shown), so the constraint is violated before per-key/per-value checks can even run.","triggerScenarios":"Passing a list of pairs, an OrderedDict-like custom mapping, or None where a dict is hinted; a DoFn yielding list(zip(keys, values)) instead of dict(zip(...)).","commonSituations":"Confusing list-of-tuples with dict; third-party mapping types not subclassing dict; returning defaultdict works (isinstance dict) but custom Mapping wrappers do not.","solutions":["Convert to a plain dict before the hinted transform: dict(pairs)","Return None-check: ensure the value is not None","If using a custom Mapping, wrap or convert with dict(obj)"],"exampleFix":"# before\nyield [(k, v) for k, v in ...]\n# after\nyield dict((k, v) for k, v in ...)","handlingStrategy":"type-guard","validationCode":"if not isinstance(obj, dict): obj = dict(obj)","typeGuard":"def is_dict(x): return isinstance(x, dict)","tryCatchPattern":null,"preventionTips":["Convert list-of-pairs and custom Mappings with dict(...) before hint checks","Guard against None before returning dict-typed values"],"tags":["python","apache-beam","type-hints","dict"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}