Skip to content

Commit

Permalink
Fix issue that can cause infinite recursion during full resolve
Browse files Browse the repository at this point in the history
The collection set_self_href has specific logic that will remove and
add data to the root catalog's resolved object cache. This is required
so that the collection cache, which is used when merging common
properties into items (a pre-1.0 STAC feature), can keep proper track
of the collection that are cached by href. However, if the root link
is not yet resolved, this cache swapping does not need to occur. In a
situation where the root was itself a collection there was an infinite
loop between resolving the root link and setting it's self href, which
in turn caused the not-quite-yet-resolved root link to go through the
logic again.

This fix will only swap cache instances out for collections during
set_self_href for root links that have already been resolved.

It adds a version of the planet disaster data locally as test case 8,
which exhibits this bug without this fix.
  • Loading branch information
lossyrob committed Oct 21, 2020
1 parent eaf8b42 commit e105c4c
Show file tree
Hide file tree
Showing 11 changed files with 867 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def set_self_href(self, href):
Overridden for collections so that the root's ResolutionObjectCache can properly
update the HREF cache.
"""
root = self.get_root()
if root is not None:
root._resolved_objects.remove(self)
root_link = self.get_root_link()
if root_link is not None and root_link.is_resolved():
root_link.target._resolved_objects.remove(self)

super().set_self_href(href)

if root is not None:
root._resolved_objects.cache(self)
if root_link is not None and root_link.is_resolved():
root_link.target._resolved_objects.cache(self)

return self

Expand Down
101 changes: 101 additions & 0 deletions tests/data-files/catalogs/planet-example-1.0.0-beta.2/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"id": "planet-disaster-data",
"stac_version": "1.0.0-beta.2",
"description": "[Planet Disaster Data](https://www.planet.com/disasterdata/) makes imagery available directly to the public, volunteers, humanitarian organizations, and other coordinating bodies in support of the International Charter for Space and Major Disasters. Data is released for individual disaster events, providing a 30 day window pre- and post-disaster. Imagery is provided under Creative Commons licenses, free of charge, with either CC-BY-SA or CC-BY-NC.",
"links": [
{
"rel": "root",
"href": "./collection.json",
"type": "application/json"
},
{
"rel": "child",
"href": "./hurricane-harvey/catalog.json",
"title": "Hurricane Harvey"
}
],
"title": "Planet Disaster Data",
"keywords": [
"disaster",
"open"
],
"providers": [
{
"name": "Planet",
"description": "Contact Planet at [planet.com/contact-sales](https://www.planet.com/contact-sales/)",
"roles": [
"producer",
"processor"
],
"url": "http://planet.com"
},
{
"name": "Planet Disaster Team",
"description": "The Planet Disaster Data Team (<disaster-team@planet.com>) has released this data as CC-BY-SA-4.0 to help disaster response",
"roles": [
"licensor"
],
"url": "https://www.planet.com/disasterdata/"
},
{
"name": "GitHub",
"description": "This catalog is hosted in the [sample-stac](https://github.com/cholmes/sample-stac) repository on GitHub",
"roles": [
"host"
],
"url": "https://github.com"
}
],
"summaries": {
"constellation": [
"skysat",
"planetscope"
],
"platform": [
"SS02",
"SSC1",
"101c"
],
"view:off_nadir": {
"min": 0.2,
"max": 27.3
},
"view:sun_elevation": {
"min": 56.3,
"max": 65.1
},
"view:sun_azimuth": {
"min": 122,
"max": 231.9
},
"eo:gsd": {
"min": 0.9,
"max": 3.7
},
"eo:cloud_cover": {
"min": 0,
"max": 24
}
},
"extent": {
"spatial": {
"bbox": [
[
-96,
28,
-93,
31
]
]
},
"temporal": {
"interval": [
[
"2017-08-28T10:00:00-08:00",
null
]
]
}
},
"license": "CC-BY-SA-4.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"id": "hurricane-harvey",
"stac_version": "1.0.0-beta.2",
"description": "Planet Disaster Data makes imagery available directly to the public, volunteers, humanitarian organizations, and other coordinating bodies in support of the International Charter for Space and Major Disasters. This catalog of data is released for Hurricane Harvey, providing a 30 day window pre- and post-disaster. Imagery is provided under Creative Commons licenses, free of charge, with either CC-BY-SA or CC-BY-NC. All new Planet scenes are made available each day, immediately after production. ",
"links": [
{
"rel": "root",
"href": "../collection.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../collection.json",
"type": "application/json"
},
{
"rel": "child",
"href": "./hurricane-harvey-0831/catalog.json",
"title": "8/31"
}
],
"title": "Hurricane Harvey"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"type": "Feature",
"stac_version": "1.0.0-beta.2",
"id": "20170831_162740_ssc1d1",
"properties": {
"datetime": "2017-08-31T16:27:42.176605Z",
"platform": "SSC1",
"constellation": "skysat",
"updated": "2017-11-01T21:09:02Z",
"created": "2017-09-01T19:37:35Z",
"gsd": 0.9,
"eo:cloud_cover": 0,
"view:azimuth": 121.3,
"view:sun_azimuth": 122,
"view:sun_elevation": 56.3,
"view:off_nadir": 27.2,
"pl:ground_control": true,
"pl:item_type": "SkySatScene",
"pl:quality_category": "standard",
"pl:strip_id": "s03_20170831T162740Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-95.46998977661133,
29.059245820517656
],
[
-95.46990394592285,
29.049491960581708
],
[
-95.44741630554199,
29.03215782622282
],
[
-95.46647071838379,
29.01797318720572
],
[
-95.46561241149902,
29.016997452585333
],
[
-95.46509742736816,
29.017072509421837
],
[
-95.44072151184082,
28.997931250084207
],
[
-95.28116226196289,
28.872261720487128
],
[
-95.26768684387207,
28.87241204397036
],
[
-95.25609970092773,
28.884888134910938
],
[
-95.28794288635254,
28.910737431999245
],
[
-95.27498245239258,
28.924335785215973
],
[
-95.24365425109863,
28.89969215375586
],
[
-95.23927688598633,
28.90405029511776
],
[
-95.23979187011719,
28.929143616007288
],
[
-95.26897430419922,
28.951677350293465
],
[
-95.35978317260742,
29.022626563968657
],
[
-95.4081916809082,
29.061796677850424
],
[
-95.42673110961913,
29.048441489877778
],
[
-95.44741630554199,
29.064872627755797
],
[
-95.46260833740233,
29.06442249447776
],
[
-95.46998977661133,
29.059245820517656
]
]
]
},
"links": [
{
"rel": "collection",
"href": "../../../collection.json"
},
{
"rel": "root",
"href": "../../../collection.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../catalog.json",
"type": "application/json"
}
],
"assets": {
"thumbnail": {
"href": "https://storage.googleapis.com/pdd-stac/disasters/hurricane-harvey/0831/SkySat_Freeport_s03_20170831T162740Z.png",
"type": "image/png",
"title": "Thumbnail",
"roles": [
"thumbnail"
]
},
"visual": {
"href": "https://storage.googleapis.com/pdd-stac/disasters/hurricane-harvey/0831/SkySat_Freeport_s03_20170831T162740Z.tif",
"type": "image/vnd.stac.geotiff; cloud-optimized=true",
"title": "SkySatScene Visual GeoTIFF",
"pl:type": "https://api.planet.com/data/v1/asset-types/ortho_visual",
"roles": [
"data"
]
}
},
"bbox": [
-95.46998977661133,
28.872261720487128,
-95.23927688598633,
29.064872627755797
],
"stac_extensions": [
"eo",
"view"
],
"collection": "planet-disaster-data"
}
Loading

0 comments on commit e105c4c

Please sign in to comment.