-
Notifications
You must be signed in to change notification settings - Fork 25
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
No CRUD generation support for ARRAY types. #109
Comments
@gmos Thanks for reporting this.
In the example below, the Is the problem when trying to post a new value back? |
@gmos @dantownsend |
@sinisaos Thanks for checking that. |
@gmos Cool, thanks - that's really useful. We'll investigate. |
Here is the column definition from the Table subclass:
And here the automatic creation of the lot.
Side question: why do I need a cast to get rid of the type warning? AM I doing something wrong assigning a PiccoloCRUD instance to the FastAPIwrapper? |
@gmos The type error might be because you're using We probably just need to update this type annotation to be
|
@dantownsend Problem is when you use |
@sinisaos Well remembered - I forgot about that. I wonder if we can add a custom validator to the Pydantic model: |
@dantownsend I think I found a problem in piccolo_api/piccolo_api/fastapi/endpoints.py Line 401 in 8b66ff3
ModeField.type_ shows the wrong type (class int or str insted List[int] or List[str] ).We need to change the line 401 to this type_ = _field.outer_type_ and the result is.
Then I add an extra check in def _parse_params(self, params: QueryParams) -> t.Dict[str, t.Any]:
params_map: t.Dict[str, t.Any] = {
i[0]: [j[1] for j in i[1]]
for i in itertools.groupby(params.multi_items(), lambda x: x[0])
}
array_columns = [
i._meta.name
for i in self.table._meta.columns
if i.value_type == list
]
output = {}
for key, value in params_map.items():
if key.endswith("[]") or key.rstrip("[]") in array_columns:
# Is either an array, or multiple values have been passed in
# for another field.
key = key.rstrip("[]")
elif len(value) == 1:
value = value[0]
output[key] = value
return output And result is
@gmos Can you please check this on your local |
@sinisaos That's some good investigative work - thanks. When we make this change we'll also have to update Piccolo Admin at the same time. |
@sinisaos Ah, just realised you managed to make it compatible with the current Piccolo Admin, great. |
@dantownsend Yes, Piccolo Admin works. If you want I can do PR. |
@sinisaos That would be great, thanks |
I've released it to PyPI now - version 0.29.2. Seems to fix the problem. Thanks both. |
At version 0.29.0 there seems to be no support for ARRAY types in the CRUD generation.
Code is generated, but an ARRAY of VARCHAR comes out as a single Varchar, and the field cannot be properly used.
In the Piccolo Admin the Arrays of Varchar are handled ok. Are there already plans to support Array types in CRUD?
The text was updated successfully, but these errors were encountered: