Plugin Version
v0.6.0
Proposed functionality
Support partial (conditional) unique constraints on Custom Object Types — i.e. a uniqueness constraint that only applies to rows matching a predicate, backed by a Postgres partial unique index (UniqueConstraint(condition=Q(...))). The natural way to add this is as an optional condition on each entry of the compound-uniqueness constraints block proposed separately (see the related feature request for multi-field uniqueness), encoded as a simple query dict mirroring the existing related_object_filter convention already used elsewhere in the schema. Today the per-field unique boolean has no notion of a predicate, and the portable schema has no unique_condition / constraints[].condition property anywhere.
Use case
Several plugins need uniqueness that only applies to a subset of rows:
- netbox-inventory's
Asset.asset_tag must be globally unique only among rows with no owning_tenant set: UniqueConstraint('asset_tag', condition=Q(owning_tenant__isnull=True)).
- netbox-inventory's
InventoryItemGroup and AssetRole require name to be unique only among top-level rows: UniqueConstraint(fields=('name',), condition=Q(parent__isnull=True)).
- netbox-acls'
ACLAssignment enforces per-address-family uniqueness only for interface-level assignments: UniqueConstraint(..., condition=~Q(direction=NONE)).
This gap affects 2 of the 9 plugins surveyed, both of which are also blocked by plain compound uniqueness — so this should be designed alongside, not instead of, that broader constraints feature.
External dependencies
None. Depends on / should be designed together with the compound-uniqueness (unique_together / UniqueConstraint) feature.
Plugin Version
v0.6.0
Proposed functionality
Support partial (conditional) unique constraints on Custom Object Types — i.e. a uniqueness constraint that only applies to rows matching a predicate, backed by a Postgres partial unique index (
UniqueConstraint(condition=Q(...))). The natural way to add this is as an optionalconditionon each entry of the compound-uniquenessconstraintsblock proposed separately (see the related feature request for multi-field uniqueness), encoded as a simple query dict mirroring the existingrelated_object_filterconvention already used elsewhere in the schema. Today the per-fielduniqueboolean has no notion of a predicate, and the portable schema has nounique_condition/constraints[].conditionproperty anywhere.Use case
Several plugins need uniqueness that only applies to a subset of rows:
Asset.asset_tagmust be globally unique only among rows with noowning_tenantset:UniqueConstraint('asset_tag', condition=Q(owning_tenant__isnull=True)).InventoryItemGroupandAssetRolerequirenameto be unique only among top-level rows:UniqueConstraint(fields=('name',), condition=Q(parent__isnull=True)).ACLAssignmentenforces per-address-family uniqueness only for interface-level assignments:UniqueConstraint(..., condition=~Q(direction=NONE)).This gap affects 2 of the 9 plugins surveyed, both of which are also blocked by plain compound uniqueness — so this should be designed alongside, not instead of, that broader constraints feature.
External dependencies
None. Depends on / should be designed together with the compound-uniqueness (
unique_together/UniqueConstraint) feature.