Skip to content

Commit d299420

Browse files
authored
fix: use dict for external collection links (#85)
use a dict instead of a stac_pydantic link object for links from external collections
1 parent 2c4ae12 commit d299420

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

stac_fastapi/eodag/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from stac_fastapi.types.rfc3339 import str_to_interval
3939
from stac_fastapi.types.search import BaseSearchPostRequest
4040
from stac_fastapi.types.stac import Collection, Collections, Item, ItemCollection
41-
from stac_pydantic.links import Links, Relations
41+
from stac_pydantic.links import Relations
4242
from stac_pydantic.shared import MimeTypes
4343

4444
from eodag import EOProduct, SearchResult
@@ -154,8 +154,11 @@ def has_ecmwf_search_plugin(federation_backends, request):
154154
):
155155
extension_names.remove("CollectionOrderExtension")
156156

157-
extra_links = (collection.links or Links([])).root
158-
extended_coll_links = Links(extended_collection.get("links", [])).root
157+
if collection.links:
158+
extra_links = [link.model_dump() for link in collection.links.root]
159+
else:
160+
extra_links = []
161+
extended_coll_links = extended_collection.get("links", [])
159162
extended_collection["links"] = CollectionLinks(
160163
collection_id=extended_collection["id"],
161164
request=request,
@@ -411,7 +414,7 @@ async def item_collection(
411414
item_collection = self._search_base(search_request, request)
412415
extension_names = [type(ext).__name__ for ext in self.extensions]
413416
links = ItemCollectionLinks(collection_id=collection_id, request=request).get_links(
414-
extensions=extension_names, extra_links=Links(item_collection["links"]).root
417+
extensions=extension_names, extra_links=item_collection["links"]
415418
)
416419
item_collection["links"] = links
417420
return item_collection

stac_fastapi/eodag/models/links.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import attr
2424
import orjson
2525
from stac_fastapi.types.requests import get_base_url
26-
from stac_pydantic.links import Link, Relations
26+
from stac_pydantic.links import Relations
2727
from stac_pydantic.shared import MimeTypes
2828
from starlette.requests import Request
2929

@@ -105,7 +105,7 @@ def create_links(self, extensions: list[str]) -> list[dict[str, Any]]:
105105
def get_links(
106106
self,
107107
extensions: list[str],
108-
extra_links: Optional[list[Link]] = None,
108+
extra_links: Optional[list[dict[str, Any]]] = None,
109109
request_json: Optional[dict[str, Any]] = None,
110110
) -> list[dict[str, Any]]:
111111
"""
@@ -129,9 +129,11 @@ def get_links(
129129
# to be stored in pgstac and for the hrefs in the
130130
# links of response STAC objects to be resolved
131131
# to the request url.
132-
for link in extra_links:
133-
link.href = self.resolve(link.href)
134-
links += [link.model_dump() for link in extra_links if link.rel not in INFERRED_LINK_RELS]
132+
links += [
133+
{**link, "href": self.resolve(link["href"])}
134+
for link in extra_links
135+
if link["rel"] not in INFERRED_LINK_RELS
136+
]
135137

136138
return links
137139

0 commit comments

Comments
 (0)