Skip to content

Commit 602d790

Browse files
committed
add tests and update changelog
1 parent 493fe05 commit 602d790

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
Note: Minor version `0.X.0` update might break the API, It's recommended to pin geojson-pydantic to minor version: `geojson-pydantic>=0.6,<0.7`
88

9+
## [1.0.1] - 2023-10-04
10+
11+
### Fixed
12+
13+
* Model serialization when using include/exclude (ref: https://github.com/developmentseed/geojson-pydantic/pull/148)
14+
915
## [1.0.0] - 2023-07-24
1016

1117
### Fixed
@@ -342,7 +348,8 @@ Although the type file was added in `0.2.0` it wasn't included in the distribute
342348
### Added
343349
- Initial Release
344350

345-
[unreleased]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.0...HEAD
351+
[unreleased]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.1...HEAD
352+
[1.0.1]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.0...1.0.1
346353
[1.0.0]: https://github.com/developmentseed/geojson-pydantic/compare/0.6.3...1.0.0
347354
[0.6.3]: https://github.com/developmentseed/geojson-pydantic/compare/0.6.2...0.6.3
348355
[0.6.2]: https://github.com/developmentseed/geojson-pydantic/compare/0.6.1...0.6.2

geojson_pydantic/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def clean_model(self, serializer: Any, info: SerializationInfo) -> Dict[str, Any
6161
# This seems like the best way to have the least amount of unexpected consequences.
6262
# We want to avoid forcing values in `exclude_none` or `exclude_unset` which could
6363
# cause issues or unexpected behavior for downstream users.
64+
# ref: https://github.com/pydantic/pydantic/issues/6575
6465
data: Dict[str, Any] = serializer(self)
6566

6667
# Only remove fields when in JSON mode.

tests/test_features.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ def test_feature_serializer():
321321
assert "bbox" in f.model_dump()
322322
assert "id" in f.model_dump()
323323

324+
# Exclude
325+
assert "bbox" not in f.model_dump(exclude={"bbox"})
326+
assert "bbox" not in list(json.loads(f.model_dump_json(exclude={"bbox"})).keys())
327+
328+
# Include
329+
assert ["bbox"] == list(f.model_dump(include={"bbox"}).keys())
330+
assert ["bbox"] == list(json.loads(f.model_dump_json(include={"bbox"})).keys())
331+
324332
feat_ser = json.loads(f.model_dump_json())
325333
assert "bbox" in feat_ser
326334
assert "id" in feat_ser
@@ -336,6 +344,8 @@ def test_feature_serializer():
336344
"properties": {},
337345
}
338346
)
347+
# BBOX Should'nt be present if `None`
348+
# https://github.com/developmentseed/geojson-pydantic/issues/125
339349
assert "bbox" in f.model_dump()
340350

341351
feat_ser = json.loads(f.model_dump_json())
@@ -381,6 +391,14 @@ def test_feature_collection_serializer():
381391
)
382392
assert "bbox" in fc.model_dump()
383393

394+
# Exclude
395+
assert "bbox" not in fc.model_dump(exclude={"bbox"})
396+
assert "bbox" not in list(json.loads(fc.model_dump_json(exclude={"bbox"})).keys())
397+
398+
# Include
399+
assert ["bbox"] == list(fc.model_dump(include={"bbox"}).keys())
400+
assert ["bbox"] == list(json.loads(fc.model_dump_json(include={"bbox"})).keys())
401+
384402
featcoll_ser = json.loads(fc.model_dump_json())
385403
assert "bbox" in featcoll_ser
386404
assert "bbox" in featcoll_ser["features"][0]

0 commit comments

Comments
 (0)