Skip to content

query_as! macro fails to compile with the skip attribute #2794

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

Closed
nyurik opened this issue Oct 3, 2023 · 1 comment
Closed

query_as! macro fails to compile with the skip attribute #2794

nyurik opened this issue Oct 3, 2023 · 1 comment
Labels

Comments

@nyurik
Copy link
Contributor

nyurik commented Oct 3, 2023

Bug Description

The #[sqlx(skip)] attribute on a sqlx::FromRow struct is ignored when using with the query_as! macro, but works with the query_as function. The cargo sqlx prepare doesn't seem to even get to that step.

error[E0063]: missing field `details` in initializer of `Message`
  --> tests/sqlite/fromrow.rs:21:35
   |
21 |     let message = sqlx::query_as!(Message, "SELECT 'bar' as message")
   |                                   ^^^^^^^ missing `details`

Minimal Reproduction

#[derive(sqlx::FromRow)]
struct Message {
    message: String,
    #[sqlx(skip)]
    details: Vec<String>,
}

#[sqlx_macros::test]
async fn test_from_row_with_skip() -> anyhow::Result<()> {
    let mut conn = new::<Sqlite>().await?;

    // This works
    let message: Message = sqlx::query_as("SELECT 'foo' as message")
        .fetch_one(&mut conn)
        .await?;
    assert_eq!(message.message, "foo");
    assert_eq!(message.details, Vec::<String>::new());

    // This fails to compile
    let message = sqlx::query_as!(Message, "SELECT 'bar' as message")
        .fetch_one(&mut conn)
        .await?;
    assert_eq!(message.message, "bar");
    assert_eq!(message.details, Vec::<String>::new());

    Ok(())
}

Info

  • SQLx version: e80291b2 (v3.10.12+)
  • SQLx features enabled: sqlite, macro
  • Database server and version: Sqlite
  • Operating system: Linux Mint
  • rustc --version: rustc 1.72.1 (d5c2e9c34 2023-09-13)
@nyurik nyurik added the bug label Oct 3, 2023
@abonander
Copy link
Collaborator

Not strictly a bug, see: #514

This is already noted in the docs: https://docs.rs/sqlx/latest/sqlx/macro.query_as.html

This macro does not use FromRow;

@abonander abonander closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants