-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Hi @vincentsarago, I stumbled across some unexpected behaviour in these pydantic models and thought I'd ask for guidance here!
Feature
seems to validate arbitrary dictionaries:
>>> geojson_pydantic.Feature.parse_obj({"hi this is": "not a feature"})
Feature(type='Feature', geometry=None, properties=None, id=None, bbox=None)
This seems kind of counter-productive, is this intentional? At least judging from the geojson json-schema, id
should not be optional!
Feature
validates the list["vh", "vv"]
, but not the list["not", "feature"]
. This is causing problems in my application, because the list of bands ["vv", "vh"] is incorrectly parsed into a GeoJson, even though it's just a list.
>>> geojson_pydantic.Feature.parse_obj(["vh", "vv"])
Feature(type='Feature', geometry=None, properties=None, id=None, bbox=None)
>>> geojson_pydantic.Feature.parse_obj(["not", "feature"])
ValueError Traceback (most recent call last)
File .venv/lib/python3.9/site-packages/pydantic/main.py:522, in pydantic.main.BaseModel.parse_obj()
ValueError: dictionary update sequence element #0 has length 3; 2 is required
The above exception was the direct cause of the following exception:
ValidationError Traceback (most recent call last) Cell In[4], line 1 ----> 1 geojson_pydantic.Feature.parse_obj(["not", "feature"])
File .venv/lib/python3.9/site-packages/pydantic/main.py:525, in pydantic.main.BaseModel.parse_obj()
ValidationError: 1 validation error for Feature root Feature expected dict not list (type=type_error)
This seems super strange too, do you have any ideas on why that specific list would validate and not the other? I have not been able to find another example.
I've run all these in a fresh virtual environment (Python 3.9.5) with only geojson_pydantic installed. Versions are the following:
print(geojson_pydantic.__version__)
print(pydantic.__version__)
>>> 0.5.0
>>> 1.10.2
Thanks!