{"record":{"id":"26902b3ca98eda4a","repo":"diesel-rs/diesel","slug":"diesel-embed-cannot-be-combined-with-dies","errorCode":null,"errorMessage":"`#[diesel(embed)]` cannot be combined with `#[diesel(serialize_as)]`","messagePattern":"`#\\[diesel\\(embed\\)\\]` cannot be combined with `#\\[diesel\\(serialize_as\\)\\]`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_derives/src/as_changeset.rs","lineNumber":109,"sourceCode":"                direct_field_assign.push(field_changeset_expr_serialize_as(\n                    field,\n                    table_name,\n                    ty,\n                    treat_none_as_null,\n                )?);\n                field_ty_bounds.push(generate_field_bound(\n                    field,\n                    table_name,\n                    Some(ty),\n                    None,\n                    &mut field_ty_bounds_guard,\n                    treat_none_as_null,\n                )?);\n\n                generate_borrowed_changeset = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of AsChangeset for borrowed structs\n            }\n            (Some(AttributeSpanWrapper { attribute_span, .. }), true) => {\n                return Err(syn::Error::new(\n                    *attribute_span,\n                    \"`#[diesel(embed)]` cannot be combined with `#[diesel(serialize_as)]`\",\n                ));\n            }\n            (None, true) => {\n                direct_field_ty.push(field_changeset_ty_embed(field, None));\n                direct_field_assign.push(field_changeset_expr_embed(field, None));\n                ref_field_ty.push(field_changeset_ty_embed(field, Some(quote!(&'update))));\n                ref_field_assign.push(field_changeset_expr_embed(field, Some(quote!(&))));\n            }\n            (None, false) => {\n                direct_field_ty.push(field_changeset_ty(\n                    field,\n                    table_name,\n                    None,\n                    treat_none_as_null,\n                )?);\n                direct_field_assign.push(field_changeset_expr(","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/as_changeset.rs#L91-L127","documentation":"The `AsChangeset` derive in diesel rejects a struct field annotated with both `#[diesel(embed)]` and `#[diesel(serialize_as)]`. `embed` inlines a nested struct's fields, while `serialize_as` converts the field to a different Rust type for serialization; the generated code cannot combine both transformations, so the derive emits a compile error pointing at the field's `serialize_as` attribute span.","triggerScenarios":"Deriving `AsChangeset` (usually via `#[derive(AsChangeset)]` or `AsChangeset` pulled in through `ActiveModel`-style patterns) on a struct where the same field carries both `#[diesel(embed)]` and `#[diesel(serialize_as = \"...\")]`.","commonSituations":"Developers copy a field's `serialize_as` from a pre-embed version of the struct, then add `embed` to inline a nested struct without removing the old attribute; refactoring structs to nest value objects while keeping old conversion annotations.","solutions":["Remove `#[diesel(serialize_as)]` from the embedded field and apply `serialize_as` on the inner struct's own fields instead.","Remove `#[diesel(embed)]` if the field genuinely needs type conversion during updates.","Split the struct: keep the embedded value object separate from the converted field."],"exampleFix":"// before\n#[derive(AsChangeset)]\nstruct UserChangeset {\n    #[diesel(embed)]\n    #[diesel(serialize_as = \"String\")]\n    name: MyNameWrapper,\n}\n\n// after\n#[derive(AsChangeset)]\nstruct UserChangeset {\n    #[diesel(embed)]\n    name: NameFields,\n}","handlingStrategy":"validation","validationCode":"// Attribute audit before compiling\nfn validate_field_attrs(attrs: &[&str]) -> Result<(), String> {\n    let has_embed = attrs.iter().any(|a| a.contains(\"embed\"));\n    let has_serialize_as = attrs.iter().any(|a| a.contains(\"serialize_as\"));\n    if has_embed && has_serialize_as {\n        return Err(\"a field cannot use both #[diesel(embed)] and #[diesel(serialize_as)]\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep `serialize_as` on leaf fields only; use `embed` for whole nested structs","When adding `#[diesel(embed)]` to a field, grep its existing attribute block for `serialize_as`","Run `cargo check` immediately after attribute refactors"],"tags":["diesel","derive-macro","rust","orm"],"backgroundTag":"invalid-argument-value","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}