Skip to content

bug: you can load a schema with an optional and unique attribute #6364

Open
@wvandeun

Description

@wvandeun

Component

API Server / GraphQL

Infrahub version

1.2.6

Current Behavior

You can load a schema with an attribute defined on a node, that is both optional and unique.
When this is the only unique attribute on the node, it will also be taken as the HFID implicitly.

Once the schema is loaded, you can then create multiple objects with a null value for that optional/unique attribute.

Expected Behavior

You cannot load a schema that has an optional and unique attribute. For backwards compatibility we could consider disabling this with the INFRAHUB_STRICT_MODE environment variable if required.

Steps to Reproduce

  • start instance of Infrahub
  • load this schema
---
version: "1.0"
nodes:
  - name: Object
    namespace: Testing
    attributes:
      - name: name
        kind: Text
        optional: true
        unique: true
      - name: other
        kind: Text
        optional: true
  • check the schema, notice that the HFID is set to the value of the name attribute
  • create 2 nodes with a null value for the name attribute
o1 = client.create("TestingObject", name="", other="foo")
o1.save()
o2 = client.create("TestingObject", name="", other="bar")
o2.save()

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    state/backlogThis issue is part of the backlogtype/bugSomething isn't working as expected

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions