Fix serializing optional Collection attributes #916
Merged
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.
Description:
The underlying problem is that, when creating a Collection from a dict, some values are pulled out to Collection-level attributes, e.g.
pystac/pystac/collection.py
Lines 644 to 646 in 114b1a1
However, those values are not removed from the original dictionary
d
, and that original dictionary is used to populateextra_fields
:pystac/pystac/collection.py
Line 657 in 114b1a1
This means that the
assets
attribute of a Collection isn't the only place where assets (and other attributes) are stored, and in fact when a collection is turned back into a dictionary, those assets are re-populated fromextra_fields
:pystac/pystac/catalog.py
Lines 516 to 517 in 114b1a1
This fixes the issue by popping these optional attributes out of the source dictionary, and by checking for these attributes' presence in a better way (i.e. before we were checking if lists were not None 😞).
PR Checklist:
pre-commit run --all-files
)scripts/test
)