Skip to content

Commit 546412e

Browse files
committed
Fixed #28495 -- Converted GDAL Feature.fields to strings
1 parent 4164076 commit 546412e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

django/contrib/gis/gdal/feature.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ def num_fields(self):
8282
@property
8383
def fields(self):
8484
"Return a list of fields in the Feature."
85-
return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i))
86-
for i in range(self.num_fields)]
85+
return [
86+
force_text(
87+
capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i)),
88+
self.encoding,
89+
strings_only=True
90+
) for i in range(self.num_fields)
91+
]
8792

8893
@property
8994
def geom(self):

tests/gis_tests/gdal_tests/test_ds.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def test04_features(self):
195195
# Making sure we get the proper OGR Field instance, using
196196
# a string value index for the feature.
197197
self.assertIsInstance(feat[k], v)
198+
self.assertIsInstance(feat.fields[0], str)
198199

199200
# Testing Feature.__iter__
200201
for fld in feat:

0 commit comments

Comments
 (0)