SaaShup / netbox-docker-plugin

Netbox Docker Plugin
https://saashup.com
BSD 3-Clause "New" or "Revised" License
65 stars 5 forks source link

:bug: Fix race condition in Container API #126

Open linkdd opened 6 months ago

linkdd commented 6 months ago

Decision Record

When creating or updating a container via the API, here's what happens:

sequenceDiagram
    actor Client
    participant PluginAPI
    participant Netbox
    participant Agent

    Client ->>PluginAPI: PATCH with operation=recreate, binds=[...]
    PluginAPI->>Netbox: update Container
    Netbox->>Agent: Webhook Call
    PluginAPI->>Netbox: update binds, ...
    Agent->>Netbox: write back binds=[]

Because the creation/update is not in an atomic transaction, the Agent writes back to Netbox potentially invalid data.

To alleviate this, the Client needs to first PATCH with the data for Netbox, then PATCH operation=recreate (just as you would do in the Netbox UI).

We can skip that part if we use Django transactions.

Changes

github-actions[bot] commented 6 months ago

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2177 2143 98% 90%

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: c34d54d by action🐍