Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ingestor-api)!: store STAC item as string in DynamoDB #26

Merged
merged 8 commits into from
Mar 28, 2023

Conversation

sharkinsspatial
Copy link
Member

@sharkinsspatial sharkinsspatial commented Mar 22, 2023

This PR addresses the issue raised in NASA-IMPACT/veda-data#57. The PR updates the ingestor code to serialize the STAC item property of the ingestion as a string prior to storing it in DynamoDB. Additionally, it updates the code used to deserialize ingestions queried from the DynamoDB table and load them into pgstac and adds unit test coverage for some of the ingestor code paths (which previously had no coverage).

@sharkinsspatial sharkinsspatial force-pushed the fix/item_serialization branch from a3246d4 to afc3655 Compare March 22, 2023 19:34
@sharkinsspatial sharkinsspatial force-pushed the fix/item_serialization branch from afc3655 to caee41a Compare March 22, 2023 20:50
@sharkinsspatial sharkinsspatial changed the title fix: STAC item serialization in Ingestion model. fix: stac item serialization in ingestion model Mar 22, 2023
@sharkinsspatial sharkinsspatial marked this pull request as ready for review March 25, 2023 18:30
@sharkinsspatial sharkinsspatial requested a review from alukach March 25, 2023 18:30
@alukach alukach force-pushed the fix/item_serialization branch from 4ba3bdd to bb864e0 Compare March 27, 2023 23:07
@alukach alukach force-pushed the fix/item_serialization branch from bb864e0 to ec31203 Compare March 27, 2023 23:10
Copy link
Member

@alukach alukach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @sharkinsspatial! Thanks for adding those tests. I added a few more (once some are written, it makes it so much easier to expand).

I rewrote a bit of the code to make use of fastapi.encoders.jsonable_encoder() which I think makes for slightly cleaner code.

Feeling really good about this change!

Comment on lines 76 to 88
class Config:
json_encoders = {
# Custom JSON serializer to ensure that item encodes as string.
# NOTE: when serializing, must call as ingestion.json(models_as_dict=False)
Item: lambda item: item.json(by_alias=True),
}

def json(self, *args, **kwargs):
# Update default to not represent models (e.g. `items` property) as a dict to
# allow our `json_encoders` override to properly serialize `items` property
kwargs.setdefault("models_as_dict", False)
return super().json(*args, **kwargs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharkinsspatial My rationale here is that if we need to put all this cruft in to make special considerations for serializing our Ingestion object for DynamoDB, it would probably make for cleaner code if we just put that cruft into the dynamodb_dict() method.

@alukach alukach changed the title fix: stac item serialization in ingestion model fix(stac-ingestor): stac item serialization in ingestion model Mar 27, 2023
@alukach alukach changed the title fix(stac-ingestor): stac item serialization in ingestion model fix(ingestor-api): stac item serialization in ingestion model Mar 27, 2023
@alukach alukach changed the title fix(ingestor-api): stac item serialization in ingestion model fix(ingestor-api): store stac items as string in DynamoDB Mar 27, 2023
@alukach alukach changed the title fix(ingestor-api): store stac items as string in DynamoDB fix(ingestor-api): store STAC item as string in DynamoDB Mar 27, 2023
@alukach alukach changed the title fix(ingestor-api): store STAC item as string in DynamoDB fix(ingestor-api)!: store STAC item as string in DynamoDB Mar 27, 2023
@sharkinsspatial sharkinsspatial merged commit c9d9a84 into main Mar 28, 2023
@sharkinsspatial sharkinsspatial deleted the fix/item_serialization branch March 28, 2023 00:16
alukach added a commit that referenced this pull request Mar 28, 2023
* fix: stac item serialization in ingestion model

* fix: use pydantic parsing and remove float conversion

* test: add initial test for missing ingestor coverage

* fix: fix updated psql function name changed in db bootstrapper

* style: fix black errors

* test: add utils.load_items test for new item serialization

* style: black and isort style changes

* Make use of jsonable_encoder, buildout tests for submitting STAC items

---------

Co-authored-by: Anthony Lukach <[email protected]>
alukach added a commit that referenced this pull request Mar 28, 2023
* fix: stac item serialization in ingestion model

* fix: use pydantic parsing and remove float conversion

* test: add initial test for missing ingestor coverage

* fix: fix updated psql function name changed in db bootstrapper

* style: fix black errors

* test: add utils.load_items test for new item serialization

* style: black and isort style changes

* Make use of jsonable_encoder, buildout tests for submitting STAC items

---------

Co-authored-by: Anthony Lukach <[email protected]>
github-actions bot pushed a commit that referenced this pull request Mar 28, 2023
## [2.6.3](v2.6.2...v2.6.3) (2023-03-28)

### Bug Fixes

* **ingestor-api:** store STAC item as string in DynamoDB ([#26](#26)) ([bd7a1fa](bd7a1fa))
anayeaye added a commit to NASA-IMPACT/veda-backend that referenced this pull request Feb 26, 2024
# What
Fixes the float epsg code issue caused by dynamodb serialization

Picked up the fix from
developmentseed/eoapi-cdk#26

# How test
Tested by running ingest from here:
https://mv5tl66nca.execute-api.us-west-2.amazonaws.com/
Test item:
https://vr3ofct5u8.execute-api.us-west-2.amazonaws.com/api/stac/collections/geoglam/items/CropMonitor_202205_test_2

```python
import pystac

item = pystac.Item.from_file("https://vr3ofct5u8.execute-api.us-west-2.amazonaws.com/api/stac/collections/geoglam/items/CropMonitor_202205_test_2")
print(item.properties["proj:epsg"]) # should give 4326 instead of 4326.0

4326
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants