{"record":{"id":"677830b8b7d6aabb","repo":"django/django","slug":"invalid-data-source-input-type","errorCode":null,"errorMessage":"Invalid data source input type: \"{}\".","messagePattern":"Invalid data source input type: \"(.+?)\"\\.","errorType":"exception","errorClass":"GDALException","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/gdal/raster/source.py","lineNumber":215,"sourceCode":"\n            # Set SRID\n            self.srs = ds_input.get(\"srid\")\n\n            # Set additional properties if provided\n            if \"origin\" in ds_input:\n                self.origin.x, self.origin.y = ds_input[\"origin\"]\n\n            if \"scale\" in ds_input:\n                self.scale.x, self.scale.y = ds_input[\"scale\"]\n\n            if \"skew\" in ds_input:\n                self.skew.x, self.skew.y = ds_input[\"skew\"]\n        elif isinstance(ds_input, c_void_p):\n            # Instantiate the object using an existing pointer to a gdal\n            # raster.\n            self._ptr = ds_input\n        else:\n            raise GDALException(\n                'Invalid data source input type: \"{}\".'.format(type(ds_input))\n            )\n\n    def __del__(self):\n        if self.is_vsi_based:\n            # Remove the temporary file from the VSI in-memory filesystem.\n            capi.unlink_vsi_file(force_bytes(self.name))\n        super().__del__()\n\n    def __str__(self):\n        return self.name\n\n    def __repr__(self):\n        \"\"\"\n        Short-hand representation because WKB may be very large.\n        \"\"\"\n        return \"<Raster object at %s>\" % hex(addressof(self._ptr))\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/gdal/raster/source.py#L197-L233","documentation":"Thrown by GDALRaster.__init__ when the ds_input argument is none of the accepted types (str, bytes, dict, c_void_p, or a pathlib.Path/JSON string that _preprocess_input converts). The constructor dispatches on input type to decide whether to open a file, build a VSI memory raster, create a new in-memory raster, or adopt an existing GDAL pointer; an unrecognized type leaves no valid code path. The message formats the offending Python type via type(ds_input).","triggerScenarios":"Calling GDALRaster() with an int, float, None, a list, a memoryview, a file object, an already-built GDALRaster instance, or any custom object. Also triggered when a Path/JSON preprocessing path silently returns a non-str/dict value (e.g. a third-party Path subclass that fails isinstance checks).","commonSituations":"Passing a raw file handle (open('tif')) instead of the path string; passing an integer SRID or band index expecting raster creation; passing None after a previous step returned no value; migrating code that fed GDALRaster an existing GDALRaster object rather than its ._ptr.","solutions":["Pass a file path string or pathlib.Path to an existing raster file","Pass a bytes buffer to open a raster from in-memory binary data","Pass a dict (with 'width','height','srid' keys) to create a new raster, or a JSON string matching that shape","Pass a c_void_p if you hold an existing GDAL dataset pointer"],"exampleFix":"// before\nGDALRaster(open('raster.tif'))\nGDALRaster(3857)\n// after\nGDALRaster('raster.tif')\nGDALRaster({'width': 10, 'height': 10, 'srid': 3857, 'bands': [{'data': range(100)}]})","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\nfrom ctypes import c_void_p\n\ndef validate_raster_input(ds_input):\n    if isinstance(ds_input, Path):\n        return str(ds_input)\n    if isinstance(ds_input, (str, bytes, dict, c_void_p)):\n        return ds_input\n    raise TypeError(f'Unsupported GDALRaster input type: {type(ds_input).__name__}')","typeGuard":"from pathlib import Path\nfrom ctypes import c_void_p\n\ndef is_raster_input(v) -> bool:\n    return isinstance(v, (str, bytes, dict, c_void_p, Path))","tryCatchPattern":"from django.contrib.gis.gdal.error import GDALException\ntry:\n    raster = GDALRaster(maybe_bad)\nexcept GDALException as e:\n    if 'Invalid data source input type' in str(e):\n        # normalize input then retry\n        ...\n    raise","preventionTips":["Always pass file paths as str/Path or dicts for creation","Validate dynamically-typed inputs at the boundary before reaching GDALRaster","Never pass file handles, SRIDs, or None"],"tags":["django-gis","gdal","raster","type-validation","constructor"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}