{"record":{"id":"45eed89c7e599347","repo":"django/django","slug":"must-set-coordinate-with-a-sequence-list-tuple","errorCode":null,"errorMessage":"Must set coordinate with a sequence (list, tuple, or numpy array).","messagePattern":"Must set coordinate with a sequence \\(list, tuple, or numpy array\\)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/geos/coordseq.py","lineNumber":56,"sourceCode":"\n    def __str__(self):\n        \"Return the string representation of the coordinate sequence.\"\n        return str(self.tuple)\n\n    def __getitem__(self, index):\n        \"Return the coordinate sequence value at the given index.\"\n        self._checkindex(index)\n        return self._point_getter(index)\n\n    def __setitem__(self, index, value):\n        \"Set the coordinate sequence value at the given index.\"\n        # Checking the input value\n        if isinstance(value, (list, tuple)):\n            pass\n        elif numpy and isinstance(value, numpy.ndarray):\n            pass\n        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)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/geos/coordseq.py#L38-L74","documentation":"Raised in GEOSCoordSeq.__setitem__ when the value being assigned to a coordinate index is not a list, tuple, or numpy.ndarray. Coordinate slots must receive a sequence of ordinates (e.g. (x,y) or [x,y,z]) so the setter can unpack them; scalars, strings, or generators are rejected. numpy is optional, so ndarray is only accepted if numpy is installed.","triggerScenarios":"Doing seq[i] = 5.0 (scalar), seq[i] = '5,6' (string), seq[i] = generator, or seq[i] = some_object. Also triggered when assigning a single ordinate where a tuple was expected.","commonSituations":"Treating a coordinate slot as a scalar field; passing coordinates parsed from a CSV string without splitting; forgetting to wrap lon/lat in a tuple.","solutions":["Assign a list/tuple: seq[i] = (x, y) or [x, y, z]","For numpy users: seq[i] = np.array([x, y])","Use setOrdinate(dim, index, value) to set a single ordinate instead"],"exampleFix":"// before\nseq[0] = 5.0\nseq[0] = '10 20'\n// after\nseq[0] = (10, 20)\n# or single ordinate\nseq.setX(0, 10)","handlingStrategy":"type-guard","validationCode":"from django.contrib.gis.shortcuts import numpy\n\ndef coerce_coord_value(v):\n    if isinstance(v, (list, tuple)):\n        return v\n    if numpy and isinstance(v, numpy.ndarray):\n        return v\n    raise TypeError('coordinate must be list/tuple/ndarray')","typeGuard":"from django.contrib.gis.shortcuts import numpy\n\ndef is_coord_sequence(v) -> bool:\n    return isinstance(v, (list, tuple)) or (numpy is not None and isinstance(v, numpy.ndarray))","tryCatchPattern":"try:\n    seq[i] = value\nexcept TypeError as e:\n    if 'Must set coordinate' in str(e):\n        seq[i] = tuple(value)\n    raise","preventionTips":["Always assign (x, y) or [x, y, z]","Use setX/setY/setZ for single ordinates","Avoid passing parsed strings without splitting"],"tags":["django-gis","geos","coordseq","type-validation","mutation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}