Skip to content

Major undocumented silently breaking change to nested validations #307

Description

@kyrias

It seems like the new derive implementation completely changed what's necessary for nested validations to work in a way where what previously worked now fails completely silently and there is no mention of this in the changelog. Additionally, the README still recommends the old way which silently fails.

The README still says to just slap #[validate] on a field for nested validation, which now does nothing at all, and that the following structs would return validation errors if there's something wrong in either the ContactDetails or Preference structs, which is no longer the case. Apparently you need to both slap a #[validate(nested)] on the actual child type that you want the validation to nest into and on the field in the parent struct. This is rather confusing and completely undiscoverable, and if you just add #[validate(nested)] to the field you get a completely opaque compiler error.

#[derive(Debug, Validate, Deserialize)]
struct SignupData {
   #[validate]
   contact_details: ContactDetails,
   #[validate]
   preferences: Vec<Preference>,
   #[validate(required)]
   allow_cookies: Option<bool>,
}

#[derive(Debug, Validate, Deserialize)]
struct ContactDetails {
   #[validate(email)]
   mail: String,
}

#[derive(Debug, Validate, Deserialize)]
struct Preference {
   #[validate(length(min = 4))]
   name: String,
   value: bool,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions