Skip to content

core: exclude the edited object from unique attribute checks - #27693

Merged
BeryJu merged 1 commit into
goauthentik:mainfrom
pcbeingused333:fix/object-attribute-unique-self
Nov 8, 2026
Merged

BeryJu merged 1 commit into
goauthentik:mainfrom
pcbeingused333:fix/object-attribute-unique-self

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #27679

Details

What does this PR change?

Unique object attributes no longer treat the object being saved as a conflict. ObjectAttribute.run_validation still rejects a value that another object already has, and now skips the row that is being edited. AttributesMixinSerializer passes that instance through.

Why is this change needed?

The uniqueness lookup was filter(attributes__key=value).exists() with no exclusion. On update the current object already stores the same value, so the check failed even when nothing else used it. Saving a user while leaving a unique attribute unchanged returned "Value is not unique." A value held by a different object is still rejected.

How was this tested?

test_user_attrib_validation_unique_same_user saves a user with a unique attribute, then patches that user with the same value and a new display name (expects 200) and patches a second user with that value (expects 400). Before the change the same-user patch returned 400. After the change, authentik/core/tests/test_object_attributes.py passes (13 tests). The existing collision test still fails when another user already has the value. ruff check and black --check are clean on the touched files. make all was not run.

Linked issues

closes #27679


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

AI disclosure: the code, the test, and this description were drafted with an AI coding agent (Grok).

Uniqueness matched every row with that value, including the object
being edited, so saving a user with an unchanged unique attribute
was rejected. Skip that row and still reject the value on any other
object.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 7, 2026 19:20
@netlify

netlify Bot commented Nov 7, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit b5db59a
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6aef7a18954d65ee7c6e30b5
😎 Deploy Preview https://deploy-preview-27693--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@BeryJu BeryJu changed the title fix: exclude the edited object from unique attribute checks core: exclude the edited object from unique attribute checks Nov 8, 2026
@BeryJu BeryJu added the backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 label Nov 8, 2026
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.00%. Comparing base (122f791) to head (b5db59a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27693      +/-   ##
==========================================
- Coverage   93.01%   93.00%   -0.01%     
==========================================
  Files        1237     1237              
  Lines       86277    86293      +16     
  Branches     4894     4894              
==========================================
+ Hits        80248    80258      +10     
- Misses       5942     5948       +6     
  Partials       87       87              
Flag Coverage Δ
conformance 30.37% <5.26%> (-0.05%) ⬇️
e2e 35.07% <5.26%> (+0.78%) ⬆️
integration 27.59% <5.26%> (-0.32%) ⬇️
rust 51.12% <ø> (ø)
unit 94.57% <100.00%> (+<0.01%) ⬆️
unit-migrate 94.57% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@BeryJu
BeryJu merged commit 5d2488a into goauthentik:main Nov 8, 2026
161 of 163 checks passed
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #27700

BeryJu added a commit that referenced this pull request Nov 23, 2026
…pick #27693 to version-2026.8) (#27700)

* core: exclude the edited object from unique attribute checks (#27693)

fix: exclude the edited object from unique attribute checks

Uniqueness matched every row with that value, including the object
being edited, so saving a user with an unchanged unique attribute
was rejected. Skip that row and still reject the value on any other
object.

* oops

---------

Co-authored-by: alexcastgonz <[email protected]>
Co-authored-by: Jens L. <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect implementation of Uniqueness check makes objects uneditable

2 participants