Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: uniqueness constraints are not ensured on concurrent create/update #4503

Open
fatih-acar opened this issue Sep 30, 2024 · 0 comments
Open
Labels
type/bug Something isn't working as expected

Comments

@fatih-acar
Copy link
Contributor

Component

API Server / GraphQL

Infrahub version

0.16.1

Current Behavior

Creating nodes currently that use the same value for an unique attribute is allowed and we end up with duplicate entries.

Expected Behavior

Running the above script should create only one node and subsequent creations should fail.

Steps to Reproduce

Using the following schema:

nodes:
  - name: Service
    namespace: Cloud
    display_labels:
     - name__value
    attributes:
      - name: name
        kind: Text
        unique: true

If you run the following script that creates multiple nodes with the same name attribute:

#!/usr/bin/env python3

import threading
import time
from infrahub_sdk import InfrahubClientSync

def create_node():
    client = InfrahubClientSync()
    node = client.create(kind="CloudService", data={"name": "Unique"})
    node.save()

for i in range(10):
    threading.Thread(name=f"t{i}", target=create_node).start()

time.sleep(2)

You end up with many nodes.

Additional Information

Might be related to #3272

@fatih-acar fatih-acar added the type/bug Something isn't working as expected label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

1 participant