Python API: ogr.CreateRangeFieldDomain() does not accept input of None for the min/max args
What is the bug?
ogr.CreateRangeFieldDomain() is documented at https://gdal.org/en/latest/api/python/vector_api.html#osgeo.ogr.CreateRangeFieldDomain with:
min (float, optional) -- Minimum value (can be
None). ... max (float, optional) -- Maximum value (can beNone).
I get a TypeError when trying to pass None for min or max.
Steps to reproduce the issue
The first call to CreateRangeFieldDomain() works with min 0.0 and max 1.0. The second call fails with min 0.0 and max None:
Python 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> from osgeo import ogr
>>>
>>> dsn = "dt_domains.gdb"
>>>
>>> ds = gdal.GetDriverByName("OpenFileGDB").Create(dsn, 0, 0, 0, gdal.GDT_Unknown)
/usr/lib/python3/dist-packages/osgeo/gdal.py:330: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.
warnings.warn(
>>>
>>> lyr = ds.CreateLayer("test", geom_type=ogr.wkbNone)
>>>
>>> domain1 = ogr.CreateRangeFieldDomain(
... "real_range1",
... "real 0 to 1",
... ogr.OFTReal,
... ogr.OFSTNone,
... 0.0,
... True,
... 1.0,
... True
... )
>>> ds.AddFieldDomain(domain1)
True
>>>
>>> fld_defn1 = ogr.FieldDefn("fld1", ogr.OFTReal)
>>> fld_defn1.SetDomainName("real_range1")
>>> lyr.CreateField(fld_defn1)
0
>>> domain2 = ogr.CreateRangeFieldDomain(
... "real_range2",
... "real min=0",
... ogr.OFTReal,
... ogr.OFSTNone,
... 0.0,
... True,
... None,
... True
... )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/osgeo/ogr.py", line 7095, in CreateRangeFieldDomain
return _ogr.CreateRangeFieldDomain(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'CreateRangeFieldDomain', argument 7 of type 'double'
Versions and provenance
ghcr.io/osgeo/gdal:ubuntu-full-latest
root@36b584eba22c:/# gdalinfo --version
GDAL 3.12.0dev-ce5f0f192b46eb67243a037a241e0ad010a2e378, released 2025/05/06
Additional context
I get the same result with either OpenFileGDB or GPKG.
It works in C++ to pass nullptr for min/max in OGR_RangeFldDomain_Create(). Is it possible to do the same in Python?
and with ogr.CreateRangeFieldDomainDateTime(), passing None for min or max seg faults:
>>> domain2 = ogr.CreateRangeFieldDomainDateTime(
... "datetime_range_inf_max",
... "datetime min 2000-01-01",
... "2000-01-01T00:00:00Z",
... True,
... None,
... True)
Segmentation fault (core dumped)