Skip to content

Fix array distinct rule for objects that have null/undefined items#148

Merged
thetutlage merged 2 commits into
vinejs:4.xfrom
Melchyore:fix/array-distinct
Jul 18, 2026
Merged

Fix array distinct rule for objects that have null/undefined items#148
thetutlage merged 2 commits into
vinejs:4.xfrom
Melchyore:fix/array-distinct

Conversation

@Melchyore

Copy link
Copy Markdown
Contributor

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Hi!

I noticed that helpers.isDistinct() doesn't currently ignore null and undefined values when checking uniqueness for arrays of objects, even though the documentation states that they should be ignored.

For example:

vine
  .array(
    vine.object({
      sku: vine.string().minLength(1).maxLength(10),
    })
  )
  .distinct('sku')

with:

{
  "variants": [
    { "sku": null },
    { "sku": null }
  ]
}

currently fails with a "sku is not unique" error because null values are converted to the same key during the uniqueness check.

I've updated the implementation to skip uniqueness checks whenever one or more of the fields used to build the composite key are null or undefined, matching the documented behavior and the implementation for primitive arrays.

I've opened this PR to fix that inconsistency.

@thetutlage

Copy link
Copy Markdown
Contributor

Looks good. Thanks!

Can you also update the docs to mention that not only the missing keys, the objects with undefined and null values are also skipped.

https://vinejs.dev/docs/types/array#treatment-of-objects-with-missing-keys

@thetutlage
thetutlage merged commit f5f2507 into vinejs:4.x Jul 18, 2026
6 checks passed
@Melchyore

Copy link
Copy Markdown
Contributor Author

Sure thing!

#54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants