stac-utils / titiler-pgstac

TiTiler + PgSTAC
https://stac-utils.github.io/titiler-pgstac/
MIT License
78 stars 27 forks source link

Search validation errors with pgstac 0.9.0 + #169

Closed zstatmanweil closed 1 month ago

zstatmanweil commented 1 month ago

I have worked through the demo and got everything working properly; however, when working through similar examples with my own database, I am seeing this error:

"detail": "2 validation errors for Search\n_where\n  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]\n    For further information visit https://errors.pydantic.dev/2.7/v/string_type\norderby\n  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]\n    For further information visit https://errors.pydantic.dev/2.7/v/string_type"

I am not having any trouble with the STAC item endpoints, but when I am using the STAC Collection endpoints or Search endpoints I see it. For example, I see this validation error when running the following:

tilejson = httpx.get(
    f"{raster_endpoint}/collections/{collection_id}/WebMercatorQuad/tilejson.json",
    params = (
        ("assets", "data"),  # THIS IS MANDATORY
        ("minzoom", 12),
        ("maxzoom", 19), 
    )
).json()

I am on pgstac 0.9.1 and am thinking that may be the issue so I tried the demo with the pgstac image v0.9.1 and confirmed I saw the same error and was no longer able to run the demo.

Is titiler-pgstac not compatible with pgstac 0.9.X yet? Anything easy that can be tweaked to get it working?

vincentsarago commented 1 month ago

thanks for the report, I'll have a look 🙏

zstatmanweil commented 1 month ago

I think I see the issue, and I think it may be a pgstac issue. In pgstac v0.9.1, none of the _where or orderby fields are populating in the search table, and the search_wheres is not being populated at all. I have mostly been using our database with stac-fastapi, where this hasn't been an issue as it would just affect performance. But here in titiler, it is throwing a pydantic error as it expects those columns to be populated.

I will open an issue in pgstac.

vincentsarago commented 1 month ago

we could patch titiler-pgstac and make https://github.com/stac-utils/titiler-pgstac/blob/main/titiler/pgstac/model.py#L200-L201 optional

zstatmanweil commented 1 month ago

That would be great if it doesn't affect the actual searches run. I think the search_wheres logic is mostly for caching, right?

vincentsarago commented 1 month ago

it won't affect anything on titiler-pgstac side. The search model is just used in the /info and in the /register endpoints.

I've tried a simple fix in #170 but that's not enough 😅

zstatmanweil commented 1 month ago

Ah yeah, failing a test. Interestingly _where and orderby are not constrained to not be null in the actual database.

Your suggestion does make titiler-pgstac usable for me though! It seems to be working.

vincentsarago commented 1 month ago

so there is another change in pgstac, before 0.9 when a search didn't exist, pgstac was returning a Search with Query Hash {self.input} Not Found" message

now we get psycopg.errors.NotNullViolation: null value in column "search" of relation "searches" violates not-null constraint , seems that https://github.com/stac-utils/pgstac/compare/v0.8.5...v0.9.0#diff-bc6e3521e72191870b534855e7973b456f89a1756315fb23510b50d926238f3aR51-R52 is not reached

cc @bitner