-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make feature geometry optional #47
make feature geometry optional #47
Conversation
thanks @yellowcap @geospatial-jeff can you double check that this change is ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
One note on this change. Because the Not really sure which is best. I guess there are use cases where you want to enforce that the geometry IS there, so maybe we should do the latter? |
🤔 I'm not sure to follow, can we write tests or pseudo code? |
It's just a difference in where the # Optional defined inside pydantic model
class Feature(GenericModel, Generic[Geom, Props]):
geometry: Optional[Geom]
....
# Or it can be defined in the `Geom` typevar
Geom = TypeVar("Geom", bound=Optional[Geometry]) If its declared inside the model, a user might set the feat = Feature[MultiPoint, Props]
feat(geometry=None) If it is declared in the typevar it's up to the user to define if the geometry is optional or not, which I think provides a better and more declarative interface: feat = Feature[Optional[MultiPoint], Props]
feat(geometry=None) Conversely, with the # Raises `ValidationError`
feat = Feature[MultiPoint, Props]
feat(geometry=None) |
I think I prefer the any feedback @yellowcap ? |
e5ecc3b
to
8c408ab
Compare
The question about where to put the I agree with @vincentsarago , the I changed the PR accordingly, please have another look and let me know if its ok like that. |
Codecov Report
@@ Coverage Diff @@
## master #47 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 106 106
=========================================
Hits 106 106
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
thanks @yellowcap 🙏 I'll update the changelog and the documentation and try to cut a new release today 🥳 |
Good stuff! Thanks for the help @geospatial-jeff and @vincentsarago 😺 |
What I am changing
According to the specs, the geometry attribute of a geojson Feature can be set to
null
. See https://datatracker.ietf.org/doc/html/rfc7946#section-3.2 . But the geometry in the Feature definition in geosjon-pydantic is required.How I did it
Wrap the geometry value with an
Optional[]
tag in the feature definition.How you can test it
I added a test for this case, but I am not sure if the test is sufficient the way I wrote it. I am not very familiar with pydantic.
Related Issues
Fixes #46
I came across this problem while using stac-fastapi, which uses stac-pydantic, which uses this library. The downstream issues are the following:
stac-utils/stac-pydantic#107
stac-utils/stac-fastapi#350