Skip to content

feat!: rely on database constraints for uniqueness - #60

Merged
azmeuk merged 1 commit into
mainfrom
unique-constraints
Nov 28, 2026
Merged

azmeuk merged 1 commit into
mainfrom
unique-constraints

Conversation

@azmeuk

@azmeuk azmeuk commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

A storage checked the unique values in Python before each write, so two concurrent writes could take the same value. Uniqueness now belongs to the database.

  • A unique value is unique within its resource type. RFC 7643 erratum 8279 is no longer followed.
  • unique_values and holds_any are gone. ResourceMapping.unique_attributes() is public, so a storage knows which fields need a constraint.
  • uniqueness_conflict builds the 409. Its detail tells the attribute, never the value, and the contract checks it.
  • A resource holding the same unique value twice gets a 400 before the storage is called, unless the stored resource already repeats it.
  • The in-memory storages call generate_id after the uniqueness checks, and it may return None. The asynchronous one can await. A taken identifier gives a 409.

A unique value is now unique within its resource type, and storages rely
on the unique constraints of their database. unique_values and holds_any
are removed, and ResourceMapping.unique_attributes is public.

The server refuses with a 400 a resource holding a unique value twice.
uniqueness_conflict builds a 409 that tells the attribute, never the
value.

The in-memory storages call generate_id after the uniqueness checks, and
the asynchronous one can await.
@read-the-docs-community

Copy link
Copy Markdown

@azmeuk
azmeuk enabled auto-merge November 28, 2026 14:37
@azmeuk
azmeuk merged commit 976f46c into main Nov 28, 2026
10 checks passed
@azmeuk
azmeuk deleted the unique-constraints branch November 28, 2026 14:40
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.

1 participant