Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde query extractor fails on simple enum types #371

Closed
mqudsi opened this issue Jul 7, 2018 · 8 comments
Closed

serde query extractor fails on simple enum types #371

mqudsi opened this issue Jul 7, 2018 · 8 comments
Labels
C-bug-upstream Category: bug in a dependency (including actix-net)

Comments

@mqudsi
Copy link

mqudsi commented Jul 7, 2018

It seems that something in how the contents of a query string are passed to serde is causing breakage with simple enum types.

For the enum

// #[serde(untagged)]
// #[serde(rename_all = "camelCase")]
#[derive(Deserialize)]
pub enum ResponseType {
    Token,
    Code
}

#[derive(Deserialize)]
pub struct AuthRequest {
    client_id: String,
    redirect_uri: String,
    response_type: ResponseType,
    scope: String,
}

and with the handler

fn authorize(params: Query<AuthRequest>) -> impl Responder {
    format!("Do you authorize this application to sync files on your behalf?")
}

a request to /authorize?...&response_type=code (or Code or ResponseType::Code or 1 or any of a dozen other permutations I tried) I get back an error along the lines of the following:

 DEBUG actix_web::pipeline    > Error { err: "invalid type: string \"code\", expected enum ResponseType" }


 INFO  actix_web::middleware::logger > 127.0.0.1:52722 [06/Jul/2018:22:54:00 -0500] "GET /authorize?client_id=ebb82a88-8197-11e8-85a6-fb14d7e72e94&redirect_uri=msn.com&response_type=code HTTP/1.1" 400 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" 0.000427

As you can see from the commented-out code, I also tried playing around with different serde enum representations and formatting options.

@mqudsi
Copy link
Author

mqudsi commented Jul 8, 2018

I suppose it might actually be this: nox/serde_urlencoded#35

@fafhrd91 fafhrd91 added the C-bug-upstream Category: bug in a dependency (including actix-net) label Jul 10, 2018
@fafhrd91
Copy link
Member

I don’t think we can do anything. This need bug fix from upstream.

@Dowwie am I right?

@Dowwie
Copy link
Contributor

Dowwie commented Jul 10, 2018

@fafhrd91 it seems that serde_urlencoded is no longer being maintained.. there's been a pending PR since Feb 2018 that upgrades to support enums: nox/serde_urlencoded#30

I pinged the author weeks ago but haven't gotten any response

@fafhrd91
Copy link
Member

that is unfortunate. so we need fork it or we need replacement

@DoumanAsh
Copy link
Contributor

@Dowwie I'll ping nox on IRC if he is still around there I'll ask him about crate's state

@DoumanAsh
Copy link
Contributor

Please see how you can use enum now https://github.com/actix/actix-web/blob/master/tests/test_handlers.rs#L94-L134

@mqudsi
Copy link
Author

mqudsi commented Jul 13, 2018

I don't even have to try it out, that's my code right there 😄

Thank you for the efficacious remedy.

@Roms1383
Copy link

Please see how you can use enum now https://github.com/actix/actix-web/blob/master/tests/test_handlers.rs#L94-L134

Link is outdated 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug-upstream Category: bug in a dependency (including actix-net)
Projects
None yet
Development

No branches or pull requests

5 participants