diesel-rs/diesel · error

expected `treat_none_as_null`

Error message

expected `treat_none_as_null`

What it means

Compile-time error from the deprecated changeset option parser used by #[derive(Insertable/AsChangeset)]. The first identifier inside the parentheses must be `treat_none_as_null`; any other option name in that position hits this guard. It validates the legacy `#[changeset_options(treat_none_as_null = true)]` style input. Fix: spell the option exactly as `treat_none_as_null`.

Solutions

  1. Use `treat_none_as_null = true` inside the parentheses
  2. Remove any other option keys
  3. Migrate to the current attribute syntax

Example fix

// before
#[diesel(treat_none_as_null = true)]
// after
#[diesel(treat_none_as_null(true))]
Defensive patterns

Strategy: validation

Validate before calling

// exact key required: treat_none_as_null

Prevention

When it happens

Trigger: Writing something like `#[diesel(treat_none_as_null_option(true))]` or misspelling the key inside `#[diesel(...)]` handled by the deprecated parser.

Common situations: Typos such as `treat_none_as_nul`, copying naming from other ORMs, or mixing up with newer attribute names.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07). Data as JSON: /api/errors/1f628be38139bf64. Report an issue: GitHub.

Appendix: source

Thrown at diesel_attribute_parser/src/deprecated/changeset_options.rs:22

use crate::deprecated::utils::parse_eq_and_lit_str;
use crate::notes::TREAT_NONE_AS_NULL_NOTE;

pub fn parse_changeset_options(name: Ident, input: ParseStream) -> Result<(Ident, LitBool)> {
    if input.is_empty() {
        return Err(syn::Error::new(
            name.span(),
            "unexpected end of input, expected parentheses",
        ));
    }

    let content;
    parenthesized!(content in input);

    let name: Ident = content.parse()?;
    let name_str = name.to_string();

    if name_str != "treat_none_as_null" {
        return Err(syn::Error::new(
            name.span(),
            "expected `treat_none_as_null`",
        ));
    }

    Ok((name.clone(), {
        let lit_str = parse_eq_and_lit_str(name, &content, TREAT_NONE_AS_NULL_NOTE)?;
        lit_str.parse()?
    }))
}

View on GitHub (pinned to 6fa6ed01b2)