{"record":{"id":"230620ce2f6d2407","repo":"django/django","slug":"invalid-oft-field-name-given-s","errorCode":null,"errorMessage":"Invalid OFT field name given: %s.","messagePattern":"Invalid OFT field name given: (.+?)\\.","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/gdal/feature.py","lineNumber":119,"sourceCode":"    def geom_type(self):\n        \"Return the OGR Geometry Type for this Feature.\"\n        return OGRGeomType(capi.get_fd_geom_type(self._layer._ldefn))\n\n    # #### Feature Methods ####\n    def get(self, field):\n        \"\"\"\n        Return the value of the field, instead of an instance of the Field\n        object. May take a string of the field name or a Field object as\n        parameters.\n        \"\"\"\n        field_name = getattr(field, \"name\", field)\n        return self[field_name].value\n\n    def index(self, field_name):\n        \"Return the index of the given field name.\"\n        i = capi.get_field_index(self.ptr, force_bytes(field_name))\n        if i < 0:\n            raise IndexError(\"Invalid OFT field name given: %s.\" % field_name)\n        return i\n","sourceCodeStart":101,"sourceCodeEnd":121,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/gdal/feature.py#L101-L121","documentation":"Raised by Feature.index (django/contrib/gis/gdal/feature.py:119) as an IndexError when the OGR C function OGR_F_GetFieldIndex returns a value < 0, meaning no field with the given name exists on this feature's layer definition. It is triggered indirectly by `feat['bad_name']` and `feat.get('bad_name')`.","triggerScenarios":"`feat['TypoName']`. Case mismatch (`feat['description']` vs. actual `'Description'`). Reading a field that exists in a different layer. Schema changed and the field was renamed or removed.","commonSituations":"Source data produced by a different tool with different column naming/casing. Locale or encoding differences in field names. Stale code referencing renamed columns. Whitespace in field names not stripped.","solutions":["List available fields first: `print(feat.fields)`.","Match case exactly, or normalize: `name = next((f for f in feat.fields if f.lower() == wanted.lower()), None)`.","Guard with membership check before access.","Confirm the field exists at the layer definition level with `ogrinfo`."],"exampleFix":"// before\nval = feat['Discription']   # typo -> IndexError\n// after\nname = next(f for f in feat.fields if f.lower() == 'description')\nval = feat[name].value","handlingStrategy":"validation","validationCode":"wanted = wanted.strip()\nmatch = next((f for f in feat.fields if f.lower() == wanted.lower()), None)\nif match is None:\n    raise KeyError(f'no field matching {wanted!r}; have {feat.fields}')\nval = feat[match].value","typeGuard":"def field_exists(feat, name) -> bool:\n    return name in feat.fields","tryCatchPattern":"try:\n    val = feat[name].value\nexcept IndexError:\n    val = None  # field absent; handle gracefully","preventionTips":["List feat.fields before any name-based access.","Normalize field-name case to avoid mismatches.","Treat schema as environment-dependent; never hardcode field names blindly."],"tags":["gis","gdal","ogr","feature","field-name","schema","indexerror"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}