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

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

Open
dsl81 opened this issue May 16, 2024 · 8 comments
Assignees
Labels
status: revisions needed This issue requires additional information to be actionable type: bug A confirmed report of unexpected behavior in the application

Comments

@dsl81
Copy link

dsl81 commented 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."
    ]
}
@dsl81 dsl81 added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels May 16, 2024
@dsl81
Copy link
Author

dsl81 commented 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'})

@DanSheps DanSheps added status: revisions needed This issue requires additional information to be actionable and removed status: needs triage This issue is awaiting triage by a maintainer labels May 16, 2024
@DanSheps
Copy link
Member

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.

@dsl81
Copy link
Author

dsl81 commented 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?

@DanSheps
Copy link
Member

DanSheps commented 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.

@dsl81
Copy link
Author

dsl81 commented 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
Copy link
Author

dsl81 commented 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
Copy link
Author

dsl81 commented 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
Copy link
Author

dsl81 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: revisions needed This issue requires additional information to be actionable type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants