diesel-rs/diesel

`skip_insertion` results in a compiler error

42triangles opened this issue · 4 comments

Setup

Compiling the following:

use diesel::Insertable;

#[derive(Insertable)]
struct Test {
    x: f32,
    #[diesel(skip_insertion)]
    y: f32,
}

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

with

[package]
name = "dieselstuff"
version = "0.1.0"
edition = "2021"

[dependencies]
diesel = "2.1.6"

Versions

  • Rust: rustc 1.77.2 (25ef9e3d8 2024-04-09)
  • Diesel: 2.1.6
  • Database: not applicable
  • Operating System Linux

Feature Flags

  • diesel: none

Problem Description

It errors out with:

error: unknown attribute, expected one of `embed`, `skip_insertion`, `column_name`, `sql_type`, `treat_none_as_default_value`, `treat_none_as_null`, `serialize_as`, `deserialize_as`, `select_expression`, `select_expression_type`
 --> src/main.rs:6:14
  |
6 |     #[diesel(skip_insertion)]
  |              ^^^^^^^^^^^^^^

In general, the following work (as in, they don't error out in the derive macro):

  • embed
  • column_name = ...
  • sql_type = ...
  • serialize_as = ...
  • deserialize_as = ...
  • select_expression = ...
  • select_expression_type = ...

And these don't work:

  • skip_insertion
  • treat_none_as_default_value
  • treat_none_as_null

What are you trying to accomplish?

Trying to use the Insertable derive macro

What is the expected output?

Either that it doesn't error out, or in case that the input is incorrect, an error message that is less confusing

What is the actual output?

An error message that would suggest that the input is well formed

Are you seeing any additional errors?

No

Steps to reproduce

cargo new --bin diesel-test, change Cargo.toml & main.rs appropriately, cargo +stable build

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

Thanks for opening this bug report. This is expected behaviour given your diesel version. The skip_insertion option is not contained in any release yet. The documentation lists all supported field attributes for certain derives.

Shouldn't the error message be different at least? Because while it may not yet be supported in that version; the error message is at the very least confusing.

That's correct. Seems like we somehow accidentally backported a PR that changes the error message only. I'm happy to merge a PR that reverts that + prepares another release. 45915ac is the relevant commit