Skip to content

fix function based collections without params#96

Merged
vincentsarago merged 4 commits into
developmentseed:mainfrom
jackharrhy:fix-functions-without-params
Jul 25, 2023
Merged

fix function based collections without params#96
vincentsarago merged 4 commits into
developmentseed:mainfrom
jackharrhy:fix-functions-without-params

Conversation

@jackharrhy

Copy link
Copy Markdown
Contributor

What I am changing

  • Currently, parameter-less functions are broken on startup when the Collection model is instantiated by them

How I did it

  • Handle the table dict having an explicit parameters: None properly, always default to a list to make pydantic happy

How you can test it

Create the following function

CREATE OR REPLACE FUNCTION public.test() RETURNS TABLE(foo integer, location geometry)
AS 'SELECT 1, ST_MakePoint(0,0);' LANGUAGE SQL;

Currently

Launching tipg will fail when it goes to create an instance of Collection based off of this function due to a validation error

After this PR

Launching tipg will work as expected without any validation errors

@jackharrhy

Copy link
Copy Markdown
Contributor Author

@vincentsarago if you'd like a test for this let me know and i can do that as well :)

@vincentsarago

Copy link
Copy Markdown
Member

Thanks @jackharrhy

if you'd like a test for this let me know and i can do that as well :)

Yes please 🙏

@bitner

bitner commented Jul 24, 2023

Copy link
Copy Markdown
Contributor

I might be missing something, but I don't see how this is doing anything differently than parameters=table.get("parameters", [])?

@vincentsarago

Copy link
Copy Markdown
Member

@bitner because I guess table can have parameters=None.

Maybe this tell us there is a bug and that parameters should always default to [] or not be set in table if empty

@vincentsarago

Copy link
Copy Markdown
Member

@bitner

Maybe this tell us there is a bug and that parameters should always default to [] or not be set in table if empty

This is what table look like

{'name': 'test', 'entity': 'Function', 'schema': 'public', 'parameters': None, 'properties': [{'name': 'foo', 'type': 'integer'}, {'name': 'location', 'type': 'geometry', 'geometry_type': 'Geometry'}]}

You can see that tipg_catalog function returns None for parameters

Comment thread tipg/collections.py Outdated
@vincentsarago

Copy link
Copy Markdown
Member

I have updated the code and added tests. @bitner I think we don't need to change the tipg_catalog SQL code to return [] by default for now!

@vincentsarago vincentsarago merged commit d82345b into developmentseed:main Jul 25, 2023
@jackharrhy jackharrhy deleted the fix-functions-without-params branch July 25, 2023 14:03
@jackharrhy

Copy link
Copy Markdown
Contributor Author

Thanks for taking this over and getting it sorted!

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.

3 participants