Skip to content
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

Fix #186 and related issues #221

Merged
merged 4 commits into from
Oct 28, 2020
Merged

Fix #186 and related issues #221

merged 4 commits into from
Oct 28, 2020

Conversation

lossyrob
Copy link
Member

@lossyrob lossyrob commented Oct 28, 2020

This PR fixes issues uncovered while investigating #186.

  • The merge_common_properties logic was executing in the case of a 0.9.0 item that did not have the 'commons' extension implemented. This was due to a bug in the logic that didn't account for the case where stac_extensions was not declared in the Item.
  • When the merge_common_properties logic does execute, if the collection that is referenced by the item produces a cached value that is not a Collection (for example if a collection was read in as a Catalog as described in Improve error handling when accidentally importing a Collection with Catalog #186), throw a more clear error than was previously being thrown.

The two other changes below relate to the caching changes made in #214:

  • The logic in Catalog and Collection from_dict was causing root objects to be cached twice - once with it's ID key and once when the HREF was set on the object. This changes the logic to ensure that if an object is read in with an HREF, it's cached only by its HREF.
  • set_self_href on Collection was promoted to be the implementation for all STACObjects. This method on Collection should have been deleted in Refactor caching to utilize HREFs and parent IDs #214, but is done so here.

Fixes #186

The logic around determining when to attempt to merge collection
properties into items was broken. This should only happen for STAC
0.9.0 if the Item implements the 'commons' extension. The logic was
checking for that extension in an existing list, but if the JSON did
not have a 'stac_extensions' property it was performing the
merge. This changes it to avoid the common property merge logic if no
stac_extensions property exists.
The logic in the common properties merging functionality expects a
collection (or a dict representing collection JSON) be cached
according to the ID associated with the collection property in an
Item. If something else is cached there (for example, if a collection
was read in as a Catalog) this produced a confusing error. This
changes the logic to throw a ValueError in that case.
This commit changes the behavior of the from_dict methods of Catalog
and Collection to pass in the href to the constructor so that caching
logic utilizes the HREF correctly.

This change will change behavior in that a catalog or collection that
is read in with a HREF that is different then the stated self HREF on
the object would previously use the HREF in the link. The to_dict
methods will now set the given HREF as the self link if provided, even
if there's an existing, differing self link. This should only affect
cases when there are incorrect self links in STAC objects.
This change was missed in #214. In that PR, the set_self_href logic
that existed on Collection was promoted to be the logic of all
set_self_hrefs on STACObjects. This makes this method unnecessary, and
causes duplicate calls to cache logic.
@codecov-io
Copy link

Codecov Report

Merging #221 into develop will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #221      +/-   ##
===========================================
- Coverage    92.62%   92.59%   -0.03%     
===========================================
  Files           28       28              
  Lines         3375     3364      -11     
===========================================
- Hits          3126     3115      -11     
  Misses         249      249              
Impacted Files Coverage Δ
pystac/catalog.py 90.17% <100.00%> (-0.11%) ⬇️
pystac/collection.py 96.90% <100.00%> (-0.17%) ⬇️
pystac/serialization/common_properties.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21ca951...280372d. Read the comment docs.

@lossyrob
Copy link
Member Author

Code coverage decreases because code removal; all additions tested.

@lossyrob lossyrob merged commit 0040d84 into develop Oct 28, 2020
@matthewhanson matthewhanson deleted the fix/collection-break branch March 26, 2021 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error handling when accidentally importing a Collection with Catalog
2 participants