Comments (15)
@sinisaos That would be great, thanks
from piccolo_api.
@gmos Thanks for reporting this.
PiccoloCRUD
should support arrays - there could be a bug somewhere.
In the example below, the years_nominated
field is an array. The API should render it like a list.
Is the problem when trying to post a new value back?
from piccolo_api.
@gmos @dantownsend POST
also work as expected.
from piccolo_api.
@sinisaos Thanks for checking that.
from piccolo_api.
Screenshots are from the swagger .../docs page. I expanded the root GET.
Parameters docs:
Here it goes wrong. No array structure to be found. The sensors field is depicted as a simple Varchar.
And this is when I make the actual GET call:
As you can see the response schema is good. the issue is about the generated parameter input for the root GET.
from piccolo_api.
@gmos Cool, thanks - that's really useful. We'll investigate.
from piccolo_api.
Here is the column definition from the Table subclass:
sensors = Array(
base_column=Varchar(
length=16,
null=False,
)
)
And here the automatic creation of the lot.
hoses_router = APIRouter()
hoses_crud = PiccoloCRUD(TempHoses, read_only=False)
FastAPIWrapper(
"/hoses",
fastapi_app=cast(FastAPI, hoses_router), # TODO Get away with the cast
piccolo_crud=hoses_crud,
fastapi_kwargs=FastAPIKwargs(
all_routes={"tags": ["TempHoses"]},
),
)
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?
from piccolo_api.
@gmos The type error might be because you're using FastAPIWrapper
with an APIRouter
instance, rather than a FastAPI
instance.
We probably just need to update this type annotation to be t.Union[FastAPI, APIRouter]
:
from piccolo_api.
@dantownsend Problem is when you use openapi
request url is http://localhost:8000/posts/?tags=tag
(which raise Pydantic ValidationError value is not a valid list (type=type_error.list)
) and it should be http://localhost:8000/posts/?tags[]=tag
like in Piccolo Admin or if you pass request url directly in browser to get correct result.
from piccolo_api.
@sinisaos Well remembered - I forgot about that.
I wonder if we can add a custom validator to the Pydantic model:
https://pydantic-docs.helpmanual.io/usage/validators/
from piccolo_api.
@dantownsend I think I found a problem in openapi
filters. We need to use ModeField.outer_type_
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 crud endpoints _parse_params
method for the array columns so that openapi request url
accepts multiple query params without square brackets. Method now looks like this
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
Piccolo Admin
and request directly in browser remain unchanged.
@gmos Can you please check this on your local Piccolo Api
installation and confirm that everything works.?
from piccolo_api.
@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.
from piccolo_api.
@sinisaos Ah, just realised you managed to make it compatible with the current Piccolo Admin, great.
from piccolo_api.
@dantownsend Yes, Piccolo Admin works. If you want I can do PR.
from piccolo_api.
I've released it to PyPI now - version 0.29.2.
Seems to fix the problem. Thanks both.
from piccolo_api.
Related Issues (20)
- Feature to modify body and query_parameters in `PiccoloCRUD` HOT 8
- Fix code scanning alert - Unused global variable
- Batch version of the get endpoint HOT 6
- Drop Python 3.7 support
- Catch foreign key constraint errors in `PiccoloCRUD`
- `schema_extra` param not passed to `pydantic_model_{output | optional | plural}` methods HOT 1
- Piccolo Admin API docs are not rendering
- Better error display on PATCH request
- Alpha version for Pydantic 2.0 / Piccolo 1.0a1? HOT 2
- PiccoloCRUD `post_single` return id of the inserted row instead of the row HOT 3
- Add `ne` operator
- Python 3.12 support
- RateLimitingMiddleware tests failed HOT 5
- Stop multi-dimensional arrays from breaking
- Issue with updating and bulk updating `BaseUser` via admin panel HOT 15
- Updating middleware syntax HOT 6
- Make `default-src` configurable in `CSPMiddleware`
- Hide parameter in Validators to hide Piccolo Admin table link from sidebar if the validators fail. HOT 8
- Add `excluded_paths` to `SessionsAuthBackend`
- Replace deprecated `abstractproperty`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piccolo_api.