Fallback to raw string value, when json field inside geojson isn't decodable #1470
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expected behavior and actual behavior.
I expected to successfully read the following geojson file by Fiona and leave the handling of mixed types geojson properties to lib user.
Actual behavior:
Steps to reproduce the problem.
Run the following script using the latest Fiona.
Operating system
macOS 15.1.1
Fiona and GDAL version and provenance
Fiona 1.10.1 from pip
GDAL 3.10.0 installed via Homebrew
Comment
When I flip lines, so that
[ ]
geojson property isn't first, the code doesn't fail.Fix
I propose to fall back to raw string value if json field property isn't decodable. When we look at different json values allowed by RFC, and how it's handled by json.loads() the string is the only one that requires different handling.
When geojson is processed, at the point of calling JSONField.get() we know that geojson is a valid json so the above cases are the only possible ones.
json.loads("[")
is impossible, so the decoding exception is possible only in case of the string.