{"record":{"id":"9d0681ab0fe160ca","repo":"django/django","slug":"dimension-of-value-does-not-match","errorCode":null,"errorMessage":"Dimension of value does not match.","messagePattern":"Dimension of value does not match\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/geos/coordseq.py","lineNumber":73,"sourceCode":"        else:\n            raise TypeError(\n                \"Must set coordinate with a sequence (list, tuple, or numpy array).\"\n            )\n        # Checking the dims of the input\n        if self.dims == 3 and self._z:\n            n_args = 3\n            point_setter = self._set_point_3d\n        elif self.dims == 3 and self.hasm:\n            n_args = 3\n            point_setter = self._set_point_3d_m\n        elif self.dims == 4 and self._z and self.hasm:\n            n_args = 4\n            point_setter = self._set_point_4d\n        else:\n            n_args = 2\n            point_setter = self._set_point_2d\n        if len(value) != n_args:\n            raise TypeError(\"Dimension of value does not match.\")\n        self._checkindex(index)\n        point_setter(index, value)\n\n    # #### Internal Routines ####\n    def _checkindex(self, index):\n        \"Check the given index.\"\n        if not (0 <= index < self.size):\n            raise IndexError(f\"Invalid GEOS Geometry index: {index}\")\n\n    def _checkdim(self, dim):\n        \"Check the given dimension.\"\n        if dim < 0 or dim > 3:\n            raise GEOSException(f'Invalid ordinate dimension: \"{dim:d}\"')\n\n    def _get_x(self, index):\n        return capi.cs_getx(self.ptr, index, byref(c_double()))\n\n    def _get_y(self, index):","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/geos/coordseq.py#L55-L91","documentation":"Raised in GEOSCoordSeq.__setitem__ when the length of the assigned sequence does not match the coordinate sequence's active dimension count (n_args). n_args is 2 for 2D, 3 for XYZ or XYM, and 4 for XYZM, computed from self.dims, self._z, and self.hasm. The check fires after the type check but before the index check.","triggerScenarios":"Assigning seq[i] = (x, y) to a 3D sequence (needs (x,y,z)); assigning (x,y,z) to a 2D sequence; assigning a 4-tuple to a non-M geometry; mixing Z and M dimensions. Also triggered when hasm raises NotImplementedError on GEOS<3.14 inside the dimension detection.","commonSituations":"Building a Point/LineString and forgetting the Z value; assuming all sequences are 2D; copying coordinates from a 3D source into a 2D target.","solutions":["Match the tuple length to the sequence dimension: inspect seq.dims, seq.hasz, seq.hasm first","Construct the geometry with the correct dimension from the start (Point(x,y,z=True))","Downcast coordinates before assigning: value[:2] for 2D targets"],"exampleFix":"// before\nseq[0] = (10, 20)  # but seq is 3D (XYZ)\n// after\nseq[0] = (10, 20, 0)\n# or rebuild as 2D\nGEOSGeometry('POINT(10 20)')","handlingStrategy":"validation","validationCode":"def dims_for(seq):\n    if seq.dims == 3 and seq._z:\n        return 3\n    if seq.dims == 3 and seq.hasm:\n        return 3\n    if seq.dims == 4 and seq._z and seq.hasm:\n        return 4\n    return 2\n\ndef validate_coord_for(seq, value):\n    n = dims_for(seq)\n    if len(value) != n:\n        raise ValueError(f'expected {n} ordinates, got {len(value)}')\n    return value","typeGuard":"def matches_dims(seq, value) -> bool:\n    return len(value) == dims_for(seq)","tryCatchPattern":"try:\n    seq[i] = value\nexcept TypeError as e:\n    if 'Dimension' in str(e):\n        seq[i] = tuple(value[:dims_for(seq)])\n    raise","preventionTips":["Inspect seq.dims/hasz/hasm before assigning","Construct geometries with the intended dimension upfront","Downcast 3D coords to 2D explicitly when targeting 2D"],"tags":["django-gis","geos","coordseq","dimension","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}