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

sqlx::test error message incorrectly implies migrate feature is disabled #3275

Closed
nk9 opened this issue Jun 9, 2024 · 2 comments · Fixed by #3276
Closed

sqlx::test error message incorrectly implies migrate feature is disabled #3275

nk9 opened this issue Jun 9, 2024 · 2 comments · Fixed by #3276
Labels

Comments

@nk9
Copy link
Contributor

nk9 commented Jun 9, 2024

Bug Description

Summary

Error message implies that the "migrate" feature isn't enabled when it actually is. When the feature isn't enabled, the error doesn't mention that it's necessary.

Detail

I am receiving the following error message when I use cargo test:

error: control attributes are not allowed unless the `migrate` feature is enabled and automatic test DB management is used; see docs

This error is generated on test_attr.rs:36:

    if input.sig.inputs.is_empty() {
        if !args.is_empty() {
            if cfg!(feature = "migrate") {
                return Err(syn::Error::new_spanned( // <--- line 36
                    args.first().unwrap(),
                    "control attributes are not allowed unless \
                        the `migrate` feature is enabled and \
                        automatic test DB management is used; see docs",
                )
                .into());
            }

            return Err(syn::Error::new_spanned(
                args.first().unwrap(),
                "control attributes are not allowed unless \
                    automatic test DB management is used; see docs",
            )
            .into());
        }

        return Ok(expand_simple(input));
    }

However, my setup DOES include the default migrate feature.

Cargo.toml

[package]
name = "test-rust2"
version = "0.1.0"
edition = "2021"

[dependencies]
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls"] }
🕙 00:54:42 ❯ cargo add sqlx --dry-run
    Updating crates.io index
      Adding sqlx v0.7.4 to dependencies
             Features:
             + _rt-tokio
             + any
             + json
             + macros
             + migrate
             + runtime-tokio
             + runtime-tokio-rustls
             + sqlx-macros
             + tls-rustls
             24 deactivated features
warning: aborting add due to dry run

The code above appears to give the extra "unless the migrate feature is enabled" wording only when… the migrate feature is enabled. (if cfg!(feature = "migrate")) However, the time when that caveat is relevant is when the migrate feature is not enabled. Otherwise, the error should just point to "automatic test DB management" as the issue.

Minimal Reproduction

Cargo.toml as above, with main.rs:

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    #[sqlx::test(migrations = "../sibling-dir/migrations")]
    fn name() {
        assert_eq!(1, 1);
    }
}

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: default, and runtime-tokio-rustls
  • Database server and version: Irrelevant
  • Operating system: macOS
  • rustc --version: rustc 1.78.0 (9b00956e5 2024-04-29)
@nk9 nk9 added the bug label Jun 9, 2024
@nk9 nk9 changed the title sqlx::test error message seems to be incorrect sqlx::test error message incorrectly implies migrate feature is disabled Jun 9, 2024
nk9 added a commit to nk9/sqlx that referenced this issue Jun 9, 2024
@wadefletch
Copy link

wadefletch commented Jun 14, 2024

Also experiencing this issue, though only when the fixtures argument is passed. It does not occur with a plain sqlx::test macro.

Does not cause the error message: #[sqlx::test] (Migrations are applied successfully, in this case.)
Causes the error message: #[sqlx::test(fixtures("graphs")]

Edit: This was resolved by adding a pool: PgPool arg to the test function signature.

@nk9
Copy link
Contributor Author

nk9 commented Jun 14, 2024

Yep, the code path that leads to the incorrect error is only triggered when the test macro has arguments. And adding one of the various arguments to the function enables Automatic Test DB Management, which means the error is no longer necessary.

nk9 added a commit to nk9/sqlx that referenced this issue Jul 10, 2024
nk9 added a commit to nk9/sqlx that referenced this issue Jul 10, 2024
abonander pushed a commit that referenced this issue Jul 11, 2024
jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants