Repository: ResonantGeoData/ResonantGeoData

Issue:
Regression: STAC endpoint for RasterMeta missing
This client method is not working:

```py
stac = client.imagery.get_raster(result, stac=True)
```

This is because the underlying STAC endpoint changed.

@mcovalt, is it possible to convert a Raster to STAC without using a Collection ID?



Discussion:
> is it possible to convert a Raster to STAC without using a Collection ID?

Not anymore; a STAC Item must belong to a collection per the STAC API spec. Luckily, though, this condition also holds for our data model; the collection is implicitly in the collection with ID `default` if `ChecksumFile.collection == None`.

Resolving patch:
diff --git a/django-rgd-imagery/client/rgd_imagery_client/plugin.py b/django-rgd-imagery/client/rgd_imagery_client/plugin.py
--- a/django-rgd-imagery/client/rgd_imagery_client/plugin.py
+++ b/django-rgd-imagery/client/rgd_imagery_client/plugin.py
@@ -101,11 +101,14 @@ def get_raster(self, raster_meta_id: Union[str, int, dict], stac: bool = False)
         if isinstance(raster_meta_id, dict):
             raster_meta_id = spatial_subentry_id(raster_meta_id)
 
+        r = self.session.get(f'rgd_imagery/raster/{raster_meta_id}').json()
         if stac:
-            r = self.session.get(f'rgd_imagery/raster/{raster_meta_id}/stac')
-        else:
-            r = self.session.get(f'rgd_imagery/raster/{raster_meta_id}')
-        return r.json()
+            # Get collection ID - TODO: if this is zero, will fail - could that happen?
+            collection_id = (
+                r['parent_raster']['image_set']['images'][0]['file']['collection'] or 'default'
+            )
+            r = self.session.get(f'stac/collection/{collection_id}/items/{raster_meta_id}').json()
+        return r
 
     def download_raster(
         self,
diff --git a/django-rgd-imagery/rgd_imagery/models/base.py b/django-rgd-imagery/rgd_imagery/models/base.py
--- a/django-rgd-imagery/rgd_imagery/models/base.py
+++ b/django-rgd-imagery/rgd_imagery/models/base.py
@@ -34,8 +34,9 @@ def get_processed_images(self, images=None):
         if images is None:
             images = set()
         for proc in self.processedimage_set.exclude(processed_image__in=images):
-            images.add(proc.processed_image)
-            images.update(proc.processed_image.get_processed_images(images))
+            if proc.processed_image:
+                images.add(proc.processed_image)
+                images.update(proc.processed_image.get_processed_images(images))
         return images
 
     @property
diff --git a/django-rgd-imagery/rgd_imagery/rest/viewsets.py b/django-rgd-imagery/rgd_imagery/rest/viewsets.py
--- a/django-rgd-imagery/rgd_imagery/rest/viewsets.py
+++ b/django-rgd-imagery/rgd_imagery/rest/viewsets.py
@@ -5,7 +5,7 @@
 from rgd.models.mixins import Status
 from rgd.rest.base import ModelViewSet
 from rgd.rest.mixins import TaskEventViewSetMixin
-from rgd_imagery import models, serializers
+from rgd_imagery import filters, models, serializers
 
 
 class ProcessedImageViewSet(ModelViewSet):
@@ -73,6 +73,7 @@ def data(self, *args, **kwargs):
 
 class RasterViewSet(ModelViewSet, TaskEventViewSetMixin):
     # TODO: consolidate 'RasterSerializer' and 'RasterMetaSerializer'
+    filterset_class = filters.RasterMetaFilter
 
     def get_serializer_class(self):
         if self.action in {'list', 'retrieve'}:


Test patch:
diff --git a/django-rgd-imagery/tests/test_client.py b/django-rgd-imagery/tests/test_client.py
--- a/django-rgd-imagery/tests/test_client.py
+++ b/django-rgd-imagery/tests/test_client.py
@@ -44,6 +44,14 @@ def test_inspect_raster(py_client: ImageryClient, sample_raster_multi):
             pytest.fail(f'Failed to download raster thumbnail {i}: {e}')
 
 
+@pytest.mark.django_db(transaction=True)
+def test_get_raster(py_client: ImageryClient, sample_raster_multi):
+    raster = py_client.imagery.get_raster(sample_raster_multi.pk)
+    assert raster
+    stac = py_client.imagery.get_raster(sample_raster_multi.pk, stac=True)
+    assert stac
+
+
 @pytest.mark.django_db(transaction=True)
 def test_download_raster(py_client: ImageryClient, sample_raster_multi):
     q = py_client.rgd.search(query=json.dumps(bbox), predicate='intersects')