Skip to content

Commit 5c16701

Browse files
committed
replace remove_item call with removing links
1 parent 3645114 commit 5c16701

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pystac/catalog.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,19 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
537537

538538
layout_template = LayoutTemplate(template, defaults=defaults)
539539

540-
items = list(self.get_items())
541-
for item in items:
540+
keep_item_links = []
541+
item_links = [lk for lk in self.links if lk.rel == 'item']
542+
for link in item_links:
543+
link.resolve_stac_object(root=self.get_root())
544+
item = link.target
542545
item_parts = layout_template.get_template_values(item)
543546
id_iter = reversed(parent_ids)
544547
if all(['{}'.format(id) == next(id_iter, None)
545548
for id in reversed(item_parts.values())]):
546549
# Skip items for which the sub-catalog structure already
547550
# matches the template. The list of parent IDs can include more
548551
# elements on the root side, so compare the reversed sequences.
552+
keep_item_links.append(link)
549553
continue
550554
curr_parent = self
551555
for k, v in item_parts.items():
@@ -558,9 +562,12 @@ def generate_subcatalogs(self, template, defaults=None, parent_ids=None, **kwarg
558562
curr_parent.add_child(subcat)
559563
result.append(subcat)
560564
curr_parent = subcat
561-
self.remove_item(item.id)
565+
562566
curr_parent.add_item(item)
563567

568+
# keep only non-item links and item links that have not been moved elsewhere
569+
self.links = [lk for lk in self.links if lk.rel != 'item'] + keep_item_links
570+
564571
return result
565572

566573
def save(self, catalog_type=None):

0 commit comments

Comments
 (0)