Updating of ConfigContexts via API fails when related objects are assigned #1888

Closed
opened 2025-12-29 17:20:05 +01:00 by adam · 3 comments
Owner

Originally created by @prx-nvdm on GitHub (Aug 3, 2018).

Environment

Python version: 3.5.2
NetBox version: last git version (33e45a2)

Steps to Reproduce

  1. Attempt to patch an existing ConfigContext via a PUT request to the API, with changes to one or more sites/tenants etc.
curl -X PUT \
-H "Authorization: Token <TOKEN>" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://localhost:8000/api/extras/config-contexts/ \
--data '{"tenants":[83],"id":5,"name":"Tenant_ConfigContext","description":"Tenant_ConfigContext","weight":2000,"is_active":true,"data":{}}'

Expected Behavior

The given ConfigContext should be updated succesfully.

Observed Behavior

An exception is raised:
Direct assignment to the forward side of a many-to-many set is prohibited. Use tenants.set() instead.

Originally created by @prx-nvdm on GitHub (Aug 3, 2018). ### Environment Python version: 3.5.2 NetBox version: last git version (33e45a2) ### Steps to Reproduce 1. Attempt to patch an existing ConfigContext via a PUT request to the API, with changes to one or more sites/tenants etc. ``` curl -X PUT \ -H "Authorization: Token <TOKEN>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://localhost:8000/api/extras/config-contexts/ \ --data '{"tenants":[83],"id":5,"name":"Tenant_ConfigContext","description":"Tenant_ConfigContext","weight":2000,"is_active":true,"data":{}}' ``` <!-- What did you expect to happen? --> ### Expected Behavior The given ConfigContext should be updated succesfully. <!-- What happened instead? --> ### Observed Behavior An exception is raised: `Direct assignment to the forward side of a many-to-many set is prohibited. Use tenants.set() instead.`
adam added the type: bugstatus: accepted labels 2025-12-29 17:20:05 +01:00
adam closed this issue 2025-12-29 17:20:05 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 3, 2018):

You need to use the URL for the existing ConfigContext in your request:

http://localhost:8000/api/extras/config-contexts/5/

The endpoint without a primary key is used only for listing all ConfigContexts or creating a new one.

@jeremystretch commented on GitHub (Aug 3, 2018): You need to use the URL for the existing ConfigContext in your request: ``` http://localhost:8000/api/extras/config-contexts/5/ ``` The endpoint without a primary key is used only for listing all ConfigContexts or creating a new one.
Author
Owner

@jeremystretch commented on GitHub (Aug 3, 2018):

This stemmed from an error in ValidatedModelSerializer.

@jeremystretch commented on GitHub (Aug 3, 2018): This stemmed from an error in `ValidatedModelSerializer`.
Author
Owner

@prx-nvdm commented on GitHub (Aug 6, 2018):

Thanks for the quick fix! @jeremystretch

@prx-nvdm commented on GitHub (Aug 6, 2018): Thanks for the quick fix! @jeremystretch
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1888