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 function based collections without params #96

Merged

Conversation

jackharrhy
Copy link
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
Contributor Author

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

@vincentsarago
Copy link
Member

Thanks @jackharrhy

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

Yes please 🙏

@bitner
Copy link
Contributor

bitner commented Jul 24, 2023

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

@vincentsarago
Copy link
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
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

tipg/collections.py Outdated Show resolved Hide resolved
@vincentsarago
Copy link
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
7 checks passed
@jackharrhy jackharrhy deleted the fix-functions-without-params branch July 25, 2023 14:03
@jackharrhy
Copy link
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