Skip to content

fix: exclude revision family from duplicate IPN check#12020

Open
bvweerd wants to merge 1 commit into
inventree:masterfrom
bvweerd:fix/duplicate-ipn-revision-validation
Open

fix: exclude revision family from duplicate IPN check#12020
bvweerd wants to merge 1 commit into
inventree:masterfrom
bvweerd:fix/duplicate-ipn-revision-validation

Conversation

@bvweerd
Copy link
Copy Markdown

@bvweerd bvweerd commented May 27, 2026

When PART_ALLOW_DUPLICATE_IPN is False, saving a revision that shares the same IPN as its parent incorrectly raised a "Duplicate IPN not allowed" error. Revisions of the same part are expected to share the same IPN, so they must be excluded from the uniqueness check.

Fixes #12017

When PART_ALLOW_DUPLICATE_IPN is False, saving a revision that shares
the same IPN as its parent incorrectly raised a "Duplicate IPN not
allowed" error. Revisions of the same part are expected to share the
same IPN, so they must be excluded from the uniqueness check.

Fixes inventree#12017
@bvweerd bvweerd requested a review from SchrodingersGat as a code owner May 27, 2026 11:00
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 5999d5f
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a16ced615efec000851fdac

@SchrodingersGat
Copy link
Copy Markdown
Member

The PART_ALLOW_DUPLICATE_IPN option is intended to enforce global uniqueness of IPN values

@bvweerd
Copy link
Copy Markdown
Author

bvweerd commented May 27, 2026

But how is it then that you're allowed to make a revision item with the same IPN, although the allow duplicate IPN is false, but not unlock the part?

Looking at the code in validate_unique(), the model itself already has a check (line 1053) that explicitly allows the same IPN across different revisions, as long as the combination of Name + IPN + Revision is unique:

  if (self.revision or self.IPN) and (
      Part.objects.exclude(pk=self.pk)
      .filter(name=self.name, revision=self.revision, IPN=self.IPN)
      .exists()
  ):
      raise ValidationError('Part with this Name, IPN and Revision already exists.')

This check implicitly permits two parts to share the same IPN as long as their revision differs.

Also referring to #1112 (comment)

@matmair
Copy link
Copy Markdown
Member

matmair commented May 27, 2026

IMO: unique means unique; not unique together with another key

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.

Bug: "Duplicate IPN not allowed" error when unlocking an existing part

3 participants