Replies: 5 comments
-
|
Unfortunately, you seem to hit the bug #2007. There is a PR to fix it (#2016), but has not been merged yet. |
Beta Was this translation helpful? Give feedback.
-
|
Looks like it's been merged as of |
Beta Was this translation helpful? Give feedback.
-
|
DONT WORK: |
Beta Was this translation helpful? Give feedback.
-
could not work. cause And the latter one
could works, this unpacks the str values in the Set object. IMO, they are not the same thing. |
Beta Was this translation helpful? Give feedback.
-
|
And also, I would like to put a complete example here. import typing as t
from fastapi import APIRouter, FastAPI
from pydantic import BaseModel, Field
class Base(BaseModel):
a: int = Field(default=0)
b: str = Field(default="None")
class Config:
orm_mode = True
class ListBase(BaseModel):
c: t.List[Base]
app = FastAPI(title="test", docs_url="/api/docs", openapi_url="/api")
r = APIRouter()
@r.get("/test",
response_model=ListBase,
response_model_exclude={"c": {"__all__": {"b"}}})
async def test_exclude():
results = {"c": [{"a": 1, "b": "aa"}, {"a": 2, "b": "ba"}]}
return results
app.include_router(r, prefix="/api")Output: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First check
Example
Here's a self-contained, minimal, reproducible, example with my use case:
Description
{"nest":[{"bar": 2, baz=3}, {"bar": 4, baz=5}], "foo": 1}baz) usingjsonable_encodernestand returns{'foo': 1}{"nest":[{"bar": 2}, {"bar": 4}], "foo": 1}.Environment
Additional context
I followed along with issue #2594 and it said the behaviour explained in https://pydantic-docs.helpmanual.io/usage/exporting_models/#advanced-include-and-exclude should work but this doesn't seem to be the case.
What am I doing wrong? :<
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions