Skip to content

FromRequest derive with Option<T> field unexpected semantics #3623

@shikhar

Description

@shikhar
  • I have looked for existing issues (including closed) about this

Bug Report

Version

0.8.8

Platform

25.2.0 Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020 arm64

Crates

axum-macros

Description

#[derive(FromRequest)]
#[from_request(rejection(MyError))]
pub struct Args {
    #[from_request(via(Path))]
    something: String,
    #[from_request(via(Json))]
    request: Option<T>
}

What I expect: for the optional request field, I get a Some(T) only if a valid JSON body is provided. If it is invalid, it should cause a JsonRejection with the From<JsonRejection> for MyError impl.

What is happening: the expanded version is using FromRequest and .ok() to convert a JsonRejection into None.

What I think should happen: optional field should require the extractor to implement OptionalFromRequest, and use that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions