{"record":{"id":"547c46f9ef8ffd43","repo":"django/django","slug":"invalid-type-encountered-in-the-arguments","errorCode":null,"errorMessage":"Invalid type encountered in the arguments.","messagePattern":"Invalid type encountered in the arguments\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/geos/mutable_list.py","lineNumber":243,"sourceCode":"            raise ValueError(\"Cannot have more than %d items\" % self._maxlength)\n\n        self._set_list(newLen, newItems)\n\n    def _set_single_rebuild(self, index, value):\n        self._set_slice(slice(index, index + 1, 1), [value])\n\n    def _checkindex(self, index):\n        length = len(self)\n        if 0 <= index < length:\n            return index\n        if -length <= index < 0:\n            return index + length\n        raise IndexError(\"invalid index: %s\" % index)\n\n    def _check_allowed(self, items):\n        if hasattr(self, \"_allowed\"):\n            if False in [isinstance(val, self._allowed) for val in items]:\n                raise TypeError(\"Invalid type encountered in the arguments.\")\n\n    def _set_slice(self, index, values):\n        \"Assign values to a slice of the object\"\n        try:\n            valueList = list(values)\n        except TypeError:\n            raise TypeError(\"can only assign an iterable to a slice\")\n\n        self._check_allowed(valueList)\n\n        origLen = len(self)\n        start, stop, step = index.indices(origLen)\n\n        # CAREFUL: index.step and step are not the same!\n        # step will never be None\n        if index.step is None:\n            self._assign_simple_slice(start, stop, valueList)\n        else:","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/geos/mutable_list.py#L225-L261","documentation":"A TypeError from ListMixin._check_allowed (mutable_list.py:243) when the class declares an `_allowed` type/tuple and an assigned item is not an instance of it. This enforces homogeneous item types on geometries like Polygon (rings must be LinearRing) or MultiLineString (members must be LineString). The check runs on every __setitem__, _set_slice, and append path.","triggerScenarios":"Assigning a Point to a Polygon's ring list; appending a LineString to a MultiPoint; assigning a plain tuple where a LinearRing instance is required; mixing concrete geometry subclasses within a collection.","commonSituations":"Treating ring slots as coordinate lists rather than LinearRing objects; building multi-geometries from heterogeneously typed members; converting between geometry collections without explicit construction.","solutions":["Construct the correct type before assignment (e.g. build a LinearRing, then append).","Inspect geom._allowed to learn the required type.","Use the concrete constructor (Polygon([...]) ) rather than mutating the ring list directly."],"exampleFix":"// before\npoly[0] = [(0, 0), (1, 1), (2, 0), (0, 0)]  # tuple not allowed\n// after\nfrom django.contrib.gis.geos import LinearRing\npoly[0] = LinearRing([(0, 0), (1, 1), (2, 0), (0, 0)])","handlingStrategy":"type-guard","validationCode":"def assign_ring(poly, idx, ring):\n    if not isinstance(ring, poly._allowed):\n        from django.contrib.gis.geos import LinearRing\n        ring = LinearRing(ring)\n    poly[idx] = ring","typeGuard":"def is_allowed_item(geom, item) -> bool:\n    allowed = getattr(geom, '_allowed', None)\n    return allowed is None or isinstance(item, allowed)","tryCatchPattern":null,"preventionTips":["Construct the correct concrete type before assignment.","Inspect geom._allowed to learn the required type.","Use the concrete constructor instead of mutating the list directly."],"tags":["django","gis","geos","listmixin","type-error","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}