mirror of https://github.com/tiangolo/fastapi.git
add test for invalid mapping
This commit is contained in:
parent
2251c78e14
commit
b0109cd399
|
|
@ -251,11 +251,11 @@ def is_scalar_sequence_field(field: ModelField) -> bool:
|
|||
|
||||
|
||||
def is_scalar_mapping_field(field: ModelField) -> bool:
|
||||
if (field.shape in mapping_shapes) and not lenient_issubclass(
|
||||
field.type_, BaseModel
|
||||
if (
|
||||
(field.shape in mapping_shapes)
|
||||
and not lenient_issubclass(field.type_, BaseModel)
|
||||
and field.sub_fields is not None
|
||||
):
|
||||
if field.sub_fields is None:
|
||||
return False
|
||||
for sub_field in field.sub_fields:
|
||||
if not is_scalar_field(sub_field):
|
||||
return False
|
||||
|
|
@ -264,11 +264,11 @@ def is_scalar_mapping_field(field: ModelField) -> bool:
|
|||
|
||||
|
||||
def is_scalar_sequence_mapping_field(field: ModelField) -> bool:
|
||||
if (field.shape in mapping_shapes) and not lenient_issubclass(
|
||||
field.type_, BaseModel
|
||||
if (
|
||||
(field.shape in mapping_shapes)
|
||||
and not lenient_issubclass(field.type_, BaseModel)
|
||||
and field.sub_fields is not None
|
||||
):
|
||||
if field.sub_fields is None:
|
||||
return False
|
||||
for sub_field in field.sub_fields:
|
||||
if not is_scalar_sequence_field(sub_field):
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
from typing import Mapping, List
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI, Query
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def test_invalid_sequence():
|
||||
with pytest.raises(AssertionError):
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
def read_items(q: Mapping[str, List[List[str]]] = Query(default=None)):
|
||||
pass # pragma: no cover
|
||||
Loading…
Reference in New Issue