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

FromRow macro can't be used on a struct contains a field named "row" #3344

Closed
constlhq opened this issue Jul 13, 2024 · 2 comments · Fixed by #3356
Closed

FromRow macro can't be used on a struct contains a field named "row" #3344

constlhq opened this issue Jul 13, 2024 · 2 comments · Fixed by #3356

Comments

@constlhq
Copy link

Bug Description

Minimal Reproduction

The following code does not compile, but if I comment the pub row: i32 line , it compiles.

#[derive(Debug, FromRow)]
pub struct TileTask {
    pub zoom: i32,
    pub row: i32,
    pub col: i32,
}
error[E0599]: no method named `try_get` found for type `i32` in the current scope
 --> crates/demo/src/entity/tile/tile_task.rs:6:17
   |
6 | #[derive(Debug, FromRow)]
   |                 ^^^^^^^ method not found in `i32`
   |
  = note: this error originates in the derive macro `FromRow` (in Nightly builds, run with -Z macro-backtrace for more info)

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: ["postgres", "runtime-tokio","chrono","any"]
  • Database server and version: Postgres 12.18.1
  • Operating system: [ubuntu 22.04]
  • rustc --version: [1.79.0 (129f3b996 2024-06-10]
@abonander
Copy link
Collaborator

@constlhq can you confirm if the changes in #3356 address the issue?

abonander added a commit that referenced this issue Jul 20, 2024
…e` for `TryFrom` errors (#3356)

* chore: create regression test for #3344

* fix(derives): use a parameter name that's less likely to collide

* breaking(derives): emit `Error::ColumnDecode` when a `TryFrom` conversion fails in `FromRow`

Breaking because `#[sqlx(default)]` on an individual field or the struct itself would have previously suppressed the error. This doesn't seem like good behavior as it could result in some potentially very difficult bugs.

Instead of using `TryFrom` for these fields, just implement `From` and apply the default explicitly.

* fix: run `cargo fmt`

* fix: use correct field in `ColumnDecode`
@constlhq
Copy link
Author

🎉

jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
…e` for `TryFrom` errors (launchbadge#3356)

* chore: create regression test for launchbadge#3344

* fix(derives): use a parameter name that's less likely to collide

* breaking(derives): emit `Error::ColumnDecode` when a `TryFrom` conversion fails in `FromRow`

Breaking because `#[sqlx(default)]` on an individual field or the struct itself would have previously suppressed the error. This doesn't seem like good behavior as it could result in some potentially very difficult bugs.

Instead of using `TryFrom` for these fields, just implement `From` and apply the default explicitly.

* fix: run `cargo fmt`

* fix: use correct field in `ColumnDecode`
jrasanen pushed a commit to jrasanen/sqlx that referenced this issue Oct 14, 2024
…e` for `TryFrom` errors (launchbadge#3356)

* chore: create regression test for launchbadge#3344

* fix(derives): use a parameter name that's less likely to collide

* breaking(derives): emit `Error::ColumnDecode` when a `TryFrom` conversion fails in `FromRow`

Breaking because `#[sqlx(default)]` on an individual field or the struct itself would have previously suppressed the error. This doesn't seem like good behavior as it could result in some potentially very difficult bugs.

Instead of using `TryFrom` for these fields, just implement `From` and apply the default explicitly.

* fix: run `cargo fmt`

* fix: use correct field in `ColumnDecode`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants