request_body_to_args() — fastapi Function Reference
Architecture documentation for the request_body_to_args() function in utils.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2["request_body_to_args()"] 9e602cbf_3139_86ae_5666_97b8806942de["utils.py"] b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 -->|defined in| 9e602cbf_3139_86ae_5666_97b8806942de fc3220b9_b8bc_99f6_605f_911723c78183["solve_dependencies()"] fc3220b9_b8bc_99f6_605f_911723c78183 -->|calls| b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 5ea666fe_6840_7f7c_f45d_e67adf31134b["_extract_form_body()"] b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 -->|calls| 5ea666fe_6840_7f7c_f45d_e67adf31134b af90f630_e23a_6963_9a62_0bf9e44f6742["_validate_value_with_model_field()"] b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 -->|calls| af90f630_e23a_6963_9a62_0bf9e44f6742 0f3cd5cf_3aea_6cfe_477e_4813f1243d25["get_validation_alias()"] b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 -->|calls| 0f3cd5cf_3aea_6cfe_477e_4813f1243d25 style b8125a22_3ce8_c209_1d2b_1aaf5de6f8b2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/dependencies/utils.py lines 921–968
async def request_body_to_args(
body_fields: list[ModelField],
received_body: Optional[Union[dict[str, Any], FormData]],
embed_body_fields: bool,
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
values: dict[str, Any] = {}
errors: list[dict[str, Any]] = []
assert body_fields, "request_body_to_args() should be called with fields"
single_not_embedded_field = len(body_fields) == 1 and not embed_body_fields
first_field = body_fields[0]
body_to_process = received_body
fields_to_extract: list[ModelField] = body_fields
if (
single_not_embedded_field
and lenient_issubclass(first_field.field_info.annotation, BaseModel)
and isinstance(received_body, FormData)
):
fields_to_extract = get_cached_model_fields(first_field.field_info.annotation)
if isinstance(received_body, FormData):
body_to_process = await _extract_form_body(fields_to_extract, received_body)
if single_not_embedded_field:
loc: tuple[str, ...] = ("body",)
v_, errors_ = _validate_value_with_model_field(
field=first_field, value=body_to_process, values=values, loc=loc
)
return {first_field.name: v_}, errors_
for field in body_fields:
loc = ("body", get_validation_alias(field))
value: Optional[Any] = None
if body_to_process is not None:
try:
value = body_to_process.get(get_validation_alias(field))
# If the received body is a list, not a dict
except AttributeError:
errors.append(get_missing_field_error(loc))
continue
v_, errors_ = _validate_value_with_model_field(
field=field, value=value, values=values, loc=loc
)
if errors_:
errors.extend(errors_)
else:
values[field.name] = v_
return values, errors
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does request_body_to_args() do?
request_body_to_args() is a function in the fastapi codebase, defined in fastapi/dependencies/utils.py.
Where is request_body_to_args() defined?
request_body_to_args() is defined in fastapi/dependencies/utils.py at line 921.
What does request_body_to_args() call?
request_body_to_args() calls 3 function(s): _extract_form_body, _validate_value_with_model_field, get_validation_alias.
What calls request_body_to_args()?
request_body_to_args() is called by 1 function(s): solve_dependencies.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free