vidigoat
11 hours ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
15 additions and
0 deletions
-
fastapi/encoders.py
-
tests/test_jsonable_encoder.py
|
|
|
@ -299,6 +299,7 @@ def jsonable_encoder( |
|
|
|
key, |
|
|
|
by_alias=by_alias, |
|
|
|
exclude_unset=exclude_unset, |
|
|
|
exclude_defaults=exclude_defaults, |
|
|
|
exclude_none=exclude_none, |
|
|
|
custom_encoder=custom_encoder, |
|
|
|
sqlalchemy_safe=sqlalchemy_safe, |
|
|
|
@ -307,6 +308,7 @@ def jsonable_encoder( |
|
|
|
value, |
|
|
|
by_alias=by_alias, |
|
|
|
exclude_unset=exclude_unset, |
|
|
|
exclude_defaults=exclude_defaults, |
|
|
|
exclude_none=exclude_none, |
|
|
|
custom_encoder=custom_encoder, |
|
|
|
sqlalchemy_safe=sqlalchemy_safe, |
|
|
|
|
|
|
|
@ -202,6 +202,19 @@ def test_encode_model_with_default(): |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def test_encode_model_with_default_in_container(): |
|
|
|
# exclude_defaults must be forwarded when recursing into dict values, just |
|
|
|
# like it already is for list/tuple/set items. |
|
|
|
model = ModelWithDefault(foo="foo", bar="bar") |
|
|
|
assert jsonable_encoder([model], exclude_defaults=True) == [{"foo": "foo"}] |
|
|
|
assert jsonable_encoder({"m": model}, exclude_defaults=True) == { |
|
|
|
"m": {"foo": "foo"} |
|
|
|
} |
|
|
|
assert jsonable_encoder({"m": model}, exclude_unset=True) == { |
|
|
|
"m": {"foo": "foo", "bar": "bar"} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def test_custom_encoders(): |
|
|
|
class safe_datetime(datetime): |
|
|
|
pass |
|
|
|
|