LukeMathWalker / zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
https://www.zero2prod.com
Apache License 2.0
5.43k stars 470 forks source link

Chapter 7.7.3.1 - sqlx fails to find the '.status" field on the Record struct #230

Closed volapovirk closed 8 months ago

volapovirk commented 8 months ago

I was following the book up to this point, added new migrations and applied them successfully. However, once I add

    assert_eq!(saved.status, "pending_confirmation");

to the subscribe_persists_the_new_subscriber() test, I'm getting

error[E0609]: no field `status` on type `Record`
  --> tests/api/subscriptions.rs:43:22
   |
43 |     assert_eq!(saved.status, "pending_confirmation");
   |                      ^^^^^^ unknown field
   |
   = note: available fields are: `email`, `name`

For more information about this error, try `rustc --explain E0609`.

Relevant Cargo.toml lines:

[dependencies.sqlx]
version = "0.7"
default-features = false
features = [
    "runtime-async-std",
    "tls-rustls",
    "macros",
    "postgres",
    "uuid",
    "chrono",
    "migrate",
]

I checked .sqlx directory but the cached query is updated with the new column:

{
  "db_name": "PostgreSQL",
  "query": "\n    INSERT INTO subscriptions (id, email, name, subscribed_at, status)\n    VALUES ($1, $2, $3, $4, 'pending_confirmation')\n    ",
  "describe": {
    "columns": [],
    "parameters": {
      "Left": [
        "Uuid",
        "Text",
        "Text",
        "Timestamptz"
      ]
    },
    "nullable": []
  },
  "hash": "f662f52204ac729545aafa231ee19008d7ca139a923e5f7a1e6fece3a4fa8884"
}

Tried cargo clean, cargo sqlx migrate run + cargo sqlx prepare but to no avail. Any ideas what might be wrong are appreciated.

volapovirk commented 8 months ago

Sorry, turned out I missed updating the SELECT query - so embarrassing!