Skip to content

bug: Unique constraint not applied on computed attribute leading to duplicated HFID #7924

Description

@BaptisteGi

Component

API Server / GraphQL

Infrahub version

1.5.4

Current Behavior

I use the name of my object as a HFID. It's unique and computed as jinja2 attribute.

However under certain circumstances it seems that this name could be duplicated and so my hfid as well, leading to various issues down the line.

Image

Expected Behavior

I expect the application to refuse the data before it reaches the database.

Steps to Reproduce

  • Load this schema
---
version: "1.0"

nodes:
  - name: Stuff
    namespace: Random
    display_label: name__value
    human_friendly_id:
      - name__value
    attributes:
      - name: name
        kind: Text
        computed_attribute:
          kind: Jinja2
          jinja2_template: "{{ description__value | upper }}-STUFF"
        read_only: true
        unique: true
        optional: false
      - name: description
        kind: Text
  • Then load the following object file
---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: RandomStuff
  data:
    - description: DESCRIPTION
    - description: DESCRIPTION
    - description: DESCRIPTION
    - description: DESCRIPTION

-> This will still create 4 objects, all with the same name even tho it should be unique

Additional Information

No response

Metadata

Metadata

Assignees

Labels

priority/1This issue must be fixed/implemented ASAP, it's a blocker for a releasetype/bugSomething isn't working as expected

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions