Skip to content

FromRequestParts derive macro uses wrong rejection #3160

@Turbo87

Description

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

Bug Report

Version

0.8.1

Crates

axum-macros

Description

https://docs.rs/axum/latest/axum/extract/derive.FromRequest.html#the-whole-type-at-once claims that:

The rejection will be the “via extractors”’s rejection. For the previous example that would be axum::extract::rejection::ExtensionRejection.

but from what I've found, this is incorrect. I've tried to use #[from_request(via(Query))] on a struct, assuming that the corresponding rejection would be QueryRejection, but instead axum::response::Response was put in the derived impl (documented as the default at https://docs.rs/axum/0.8.1/axum/extract/derive.FromRequest.html#the-rejection).

I assume that this is a bug in the derive macro for at least FromRequestParts, but probably FromRequest too.

Activity

added this to the 0.9 milestone on Jan 28, 2025
kyle-nweeia

kyle-nweeia commented on Mar 3, 2025

@kyle-nweeia
Contributor

@Turbo87 could you provide an example of an extractor and a handler that cause the wrong rejection to be used?

Turbo87

Turbo87 commented on Mar 9, 2025

@Turbo87
CollaboratorAuthor

I think this is roughly what I did back then:

#[derive(Debug, Deserialize, FromRequestParts)]
#[from_request(via(Query))]
pub struct QueryParams {
    message: Option<String>,
}

let result: Result<_, QueryRejection> = parts.extract::<QueryParams>().await;

if I use #[from_request(via(Query), rejection(QueryRejection))] instead it works, but not without it. this makes it difficult to use the additional information in QueryRejection in a custom HTTP response.

kyle-nweeia

kyle-nweeia commented on Mar 26, 2025

@kyle-nweeia
Contributor

@Turbo87 do you think that #3261 will solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @Turbo87@jplatte@kyle-nweeia

      Issue actions

        `FromRequestParts` derive macro uses wrong rejection · Issue #3160 · tokio-rs/axum