Inventory items update error 'The fields device, parent, name must make a unique set.' via api #9688

Closed
opened 2025-12-29 21:20:54 +01:00 by adam · 15 comments
Owner

Originally created by @dsl81 on GitHub (May 16, 2024).

requests.txt

Deployment Type

Self-hosted

NetBox Version

v4.0.2

Python Version

3.11

Steps to Reproduce

  1. Create 2 devices. id1 (9) and id2 (957)
  2. Create 2 inventory items on device with id2 by sending 2 requests:
curl -H "Authorization: Token $TOKEN" \
-H "Accept: application/json; indent=4" \
-H "Content-Type: application/json" \
https://netbox/api/dcim/inventory-items/ \
-X POST \
-d '{ "device" : "957","name" : "sfp"}'
  1. get item_id1 (5492) and item_id2 (5493)
  2. update items with data '{ "device" : "9"}'
% curl -H "Authorization: Token $TOKEN" \
-H "Accept: application/json; indent=4" \
-H "Content-Type: application/json" \
https://netbox/api/dcim/inventory-items/5492/ \
-X PATCH \
-d '{ "device" : "9"}'

same for item_id2 (5493)

Expected Behavior

receive updated inventory items

Observed Behavior

second PATCH request returns:

{
    "non_field_errors": [
        "The fields device, parent, name must make a unique set."
    ]
}
Originally created by @dsl81 on GitHub (May 16, 2024). [requests.txt](https://github.com/netbox-community/netbox/files/15403647/requests.txt) ### Deployment Type Self-hosted ### NetBox Version v4.0.2 ### Python Version 3.11 ### Steps to Reproduce 1. Create 2 devices. id1 (9) and id2 (957) 2. Create 2 inventory items on device with id2 by sending 2 requests: ``` curl -H "Authorization: Token $TOKEN" \ -H "Accept: application/json; indent=4" \ -H "Content-Type: application/json" \ https://netbox/api/dcim/inventory-items/ \ -X POST \ -d '{ "device" : "957","name" : "sfp"}' ``` 3. get item_id1 (5492) and item_id2 (5493) 4. update items with data '{ "device" : "9"}' ``` % curl -H "Authorization: Token $TOKEN" \ -H "Accept: application/json; indent=4" \ -H "Content-Type: application/json" \ https://netbox/api/dcim/inventory-items/5492/ \ -X PATCH \ -d '{ "device" : "9"}' ``` same for item_id2 (5493) ### Expected Behavior receive updated inventory items ### Observed Behavior second PATCH request returns: ``` { "non_field_errors": [ "The fields device, parent, name must make a unique set." ] } ```
adam closed this issue 2025-12-29 21:20:54 +01:00
Author
Owner

@dsl81 commented on GitHub (May 16, 2024):

Moving item with identical names to one device works in gui.
Also creating "identical" items in api works:
item3 = nb.dcim.inventory_items.create({ 'device' : 9 , 'name' : 'sfp'})

@dsl81 commented on GitHub (May 16, 2024): Moving item with identical names to one device works in gui. Also creating "identical" items in api works: item3 = nb.dcim.inventory_items.create({ 'device' : 9 , 'name' : 'sfp'})
Author
Owner

@DanSheps commented on GitHub (May 16, 2024):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.2 using raw API requests. Please re-confirm the reported behavior using raw API queries on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@DanSheps commented on GitHub (May 16, 2024): Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.2 using raw API requests. Please re-confirm the reported behavior using raw API queries on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
Author
Owner

@dsl81 commented on GitHub (May 22, 2024):

I updated issue with raw API requests. Also attached file with output.
Hope it can be reproduced though my installation is not clean. Or i should include steps for creating devices?

@dsl81 commented on GitHub (May 22, 2024): I updated issue with raw API requests. Also attached file with output. Hope it can be reproduced though my installation is not clean. Or i should include steps for creating devices?
Author
Owner

@DanSheps commented on GitHub (May 22, 2024):

I updated issue with raw API requests. Also attached file with output.
Hope it can be reproduced though my installation is not clean. Or i should include steps for creating devices?

I am unable to reproduce this following the steps provided under normal circumstances.

@DanSheps commented on GitHub (May 22, 2024): > I updated issue with raw API requests. Also attached file with output. > Hope it can be reproduced though my installation is not clean. Or i should include steps for creating devices? I am unable to reproduce this following the steps provided under normal circumstances.
Author
Owner

@dsl81 commented on GitHub (May 23, 2024):

I just made clean install and get the same issue with API. Could you please show how you move inventory items to one device with API?

@dsl81 commented on GitHub (May 23, 2024): I just made clean install and get the same issue with API. Could you please show how you move inventory items to one device with API?
Author
Owner

@dsl81 commented on GitHub (May 28, 2024):

I am unable to reproduce this following the steps provided under normal circumstances.

Do I understand correctly that you are able to make API calls to change 2 items with same name to one device?

@dsl81 commented on GitHub (May 28, 2024): > I am unable to reproduce this following the steps provided under normal circumstances. Do I understand correctly that you are able to make API calls to change 2 items with same name to one device?
Author
Owner

@dsl81 commented on GitHub (May 29, 2024):

I think i found the commit that introduced this behavior. After the discussion it should be reverted. But it seems that in case of API it remained.

constraints = (
            models.UniqueConstraint(
                fields=('device', 'parent', 'name'),
                name='%(app_label)s_%(class)s_unique_device_parent_name'
            ),
        )

are still in device_components.py. Could you check this please?

@dsl81 commented on GitHub (May 29, 2024): I think i found the [commit](https://github.com/netbox-community/netbox/issues/13741) that introduced this behavior. After the [discussion](https://github.com/netbox-community/netbox/issues/13837) it should be reverted. But it seems that in case of API it remained. ``` constraints = ( models.UniqueConstraint( fields=('device', 'parent', 'name'), name='%(app_label)s_%(class)s_unique_device_parent_name' ), ) ``` are still in device_components.py. Could you check this please?
Author
Owner

@dsl81 commented on GitHub (May 29, 2024):

I have commented lines 1256 - 1261 in dcim/models/device_components.py and API started to work as expected, but i don't know if some migrations are required.

@dsl81 commented on GitHub (May 29, 2024): I have commented lines 1256 - 1261 in dcim/models/device_components.py and API started to work as expected, but i don't know if some migrations are required.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 6, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Jun 6, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@dsl81 commented on GitHub (Jun 6, 2024):

What info can i provide to investigate the issue?

@dsl81 commented on GitHub (Jun 6, 2024): What info can i provide to investigate the issue?
Author
Owner

@dsl81 commented on GitHub (Jun 11, 2024):

The behavior still presents in 4.0.5.

@dsl81 commented on GitHub (Jun 11, 2024): The behavior still presents in 4.0.5.
Author
Owner

@DanSheps commented on GitHub (Jun 11, 2024):

So, I was able to reproduce this.

I think i found the https://github.com/netbox-community/netbox/issues/13741 that introduced this behavior. After the https://github.com/netbox-community/netbox/issues/13837 it should be reverted. But it seems that in case of API it remained.

This was not the conclusion from the discussion at all, in fact the conclusion is that you should use the inventory items unique name within the system as the name in NetBox (example: an SFP in slot 1/1/8 on a Cisco 9300-48U, would be named "Te1/1/8" (that is the name that show inventory reports. A PSU on the same switch would be named "Switch 1 - Power Supply B" if you decide to use an inventory item for that.)

I also did some digging, as per Jeremy's comment:

It is a model number, and is intended to be conveyed by the part ID field. You're free to use the fields however you like, but this would not be justification for removing the uniqueness constraint on the name field.

Further down:

As there hasn't been any further discussion in recent months, I'm going to close this out as stale. We might revisit it in the future.

People wanted the uniqueness check to be reverted, but that doesn't mean us (the maintainers) are always going to do as the community wishes as there are other considerations beyond the communities desire (such as model integrity, search and filtering) which removing a uniqueness check would all impact.

I am going to close this out as this is not a bug and a currently intended feature. You are free to open an enhancement request to request changes however we won't be removing the uniquenes check from this field but we could amend it with different criteria if there is an appropriate proposal with a supporting use case for it.

@DanSheps commented on GitHub (Jun 11, 2024): So, I was able to reproduce this. > I think i found the https://github.com/netbox-community/netbox/issues/13741 that introduced this behavior. After the https://github.com/netbox-community/netbox/issues/13837 it should be reverted. But it seems that in case of API it remained. This was not the conclusion from the discussion at all, in fact the conclusion is that you should use the inventory items unique name within the system as the name in NetBox (example: an SFP in slot 1/1/8 on a Cisco 9300-48U, would be named "Te1/1/8" (that is the name that `show inventory` reports. A PSU on the same switch would be named "Switch 1 - Power Supply B" if you decide to use an inventory item for that.) I also did some digging, as per Jeremy's comment: > It is a model number, and is intended to be conveyed by the part ID field. You're free to use the fields however you like, but this would not be justification for removing the uniqueness constraint on the name field. Further down: > As there hasn't been any further discussion in recent months, I'm going to close this out as stale. We might revisit it in the future. People wanted the uniqueness check to be reverted, but that doesn't mean us (the maintainers) are always going to do as the community wishes as there are other considerations beyond the communities desire (such as model integrity, search and filtering) which removing a uniqueness check would all impact. I am going to close this out as this is not a bug and a currently intended feature. You are free to open an enhancement request to request changes however we won't be removing the uniquenes check from this field but we could amend it with different criteria if there is an appropriate proposal with a supporting use case for it.
Author
Owner

@dsl81 commented on GitHub (Jun 13, 2024):

I believe it was be discussed somewhere but the sfp can be moved from slot 1/1/8 to slot 2/1/7 and its name should not change in my opinion.
Besides I can make identical inventory items with GUI. Why i can't do that in API?

@dsl81 commented on GitHub (Jun 13, 2024): I believe it was be discussed somewhere but the sfp can be moved from slot 1/1/8 to slot 2/1/7 and its name should not change in my opinion. Besides I can make identical inventory items with GUI. Why i can't do that in API?
Author
Owner

@DanSheps commented on GitHub (Jun 13, 2024):

I believe it was be discussed somewhere but the sfp can be moved from slot 1/1/8 to slot 2/1/7 and its name should not change in my opinion.

That is likely a bug itself.

@DanSheps commented on GitHub (Jun 13, 2024): > I believe it was be discussed somewhere but the sfp can be moved from slot 1/1/8 to slot 2/1/7 and its name should not change in my opinion. That is likely a bug itself.
Author
Owner

@dsl81 commented on GitHub (Jun 14, 2024):

If name uniqueness is mandatory from schema point of view maybe it would be more logical to make unique not ('device', 'parent', 'name') but (device', 'parent', 'name' component_type+component_id) ?
I can hardly imagine use case when i need to associate one item with another item.

@dsl81 commented on GitHub (Jun 14, 2024): If name uniqueness is mandatory from schema point of view maybe it would be more logical to make unique not ('device', 'parent', 'name') but (device', 'parent', 'name' component_type+component_id) ? I can hardly imagine use case when i need to associate one item with another item.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9688