directus icon indicating copy to clipboard operation
directus copied to clipboard

Image validation does not accept image that meets the validation conditions

Open MartinMiksovskyLaposa opened this issue 3 years ago • 2 comments

Describe the Bug

I'm receiving this validation error:

The following fields have invalid values:

image: validationError.undefined
image: validationError.undefined
image

whenever I'm trying to add an Image into my Component that should pass the validation rules.

Data model structure (simplified):

Root Component --- 1:n ---> Single item (containing image field)

Image validation on Single item:

Image->width == 800px (equal to 800px) Image->height == 330px (equal to 330px)

Provided Image metadata: 800x330, png & jpg formats

To Reproduce

  1. Create a Data Model for Root component (blank)
  2. Create a Data Model for single Item with Image field only
  3. Add a relation: Root --1:N--> Single item (one-to-many)
  4. Add validation rule to the Image field (Image->width == fixed number; Image->height == fixed number)
  5. Set all necessary permissions & page for this component
  6. Try to insert an Image on a Page containing our component that fits the validated size defined in step 4
  1. Try to save & publish the Page - Error occurs.

Errors Shown

The following fields have invalid values:

image: validationError.undefined image: validationError.undefined

What version of Directus are you using?

9.14.5

What version of Node.js are you using?

14.20.0

What database are you using?

Postgres 11

What browser are you using?

Microsoft Edge Version 103.0.1264.62 (Official build) (64-bit)

How are you deploying Directus?

Docker

MartinMiksovskyLaposa avatar Jul 26 '22 11:07 MartinMiksovskyLaposa

Validation does not fetch the required data to do this check. It will try to validate against the UUID string instead of the whole object of metadata. The extra info will need to be fetched before this validation https://github.com/directus/directus/blob/main/api/src/services/items.ts#L455

br41nslug avatar Jul 26 '22 13:07 br41nslug

@br41nslug There's tons of other issues/discussions that are effectively riffs on the same problems:

  1. Validation runs against the submitted payload, not against the merged result of existing data + payload of edits, and:
  2. Validation doesn't "expand" relational fields when "select existing" is used[^1]

[^1]: This is what you mentioned. An ID 1 won't pass validation that checks against { value: { _eq: 'rijk' }}

rijkvanzanten avatar Jul 26 '22 15:07 rijkvanzanten

Closing in favor of tracking the same bug in #14414.

azrikahar avatar Aug 17 '22 04:08 azrikahar