@@ -343,24 +343,49 @@ def _update_base_catalog(
343343 Returns:
344344 Updated Catalog object.
345345 """
346- # Load the base catalog
347346 base_catalog = Catalog .from_file (
348347 Path (self .gh_publisher .github_automation .local_clone_dir ) / catalog_path
349348 )
350349
351- # Add a link to the new item
352- base_catalog .add_link (
353- Link (
354- rel = "item" ,
355- target = f"./{ item_id } /record.json" ,
356- media_type = "application/json" ,
357- title = f"{ self .workflow_title } " ,
350+ item_href = f"./{ item_id } /record.json"
351+
352+ # Ensure the "item" link is unique
353+ def link_href (link : Link ) -> str | None :
354+ # PySTAC Link may store href in .target or .href; .get_href() resolves if base HREF set
355+ return (
356+ getattr (link , "href" , None )
357+ or getattr (link , "target" , None )
358+ or (link .get_href () if hasattr (link , "get_href" ) else None )
358359 )
360+
361+ has_item = any (
362+ (l .rel == "item" ) and (link_href (l ) == item_href )
363+ for l in base_catalog .links
359364 )
365+ if not has_item :
366+ base_catalog .add_link (
367+ Link (
368+ rel = "item" ,
369+ target = item_href ,
370+ media_type = "application/json" ,
371+ title = self .workflow_title ,
372+ )
373+ )
360374
361- # Set the self-href for the base catalog
375+ # Ensure there is exactly one "self" link
376+ base_catalog .links = [l for l in base_catalog .links if l .rel != "self" ]
362377 base_catalog .set_self_href (self_href )
363378
379+ # deduplicate by (rel, href)
380+ seen = set ()
381+ unique_links = []
382+ for l in base_catalog .links :
383+ key = (l .rel , link_href (l ))
384+ if key not in seen :
385+ unique_links .append (l )
386+ seen .add (key )
387+ base_catalog .links = unique_links
388+
364389 return base_catalog
365390
366391 def generate_workflow_experiment_records (
0 commit comments