Updating a GFK field via API does not return the new value #7937

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

Originally created by @amhn on GitHub (Apr 23, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.4.8

Python version

3.10

Steps to Reproduce

  1. Create IP-Address (do not assign object)
  2. Create Object to assign (e.g. FHRP Group
  3. curl -H "Authorization: Token $NETBOX_TOKEN" -H "Content-type: application/json" $NETBOX_SCHEME://$NETBOX_URL/api/ipam/ip-addresses/1/ -X PATCH --data '{"assigned_object_type": "ipam.fhrpgroup", "assigned_object_id":1}'

Expected Behavior

assigned_object in the response is not null.

Observed Behavior

assigned_object is null:

{
    "id": 1,
    "url": "http://localhost:8000/api/ipam/ip-addresses/1/",
    "display": "127.0.0.1/32",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "address": "127.0.0.1/32",
    "vrf": null,
    "tenant": null,
    "status": {
        "value": "active",
        "label": "Active"
    },
    "role": null,
    "assigned_object_type": "ipam.fhrpgroup",
    "assigned_object_id": 1,
    "assigned_object": null,
    "nat_inside": null,
    "nat_outside": [],
    "dns_name": "",
    "description": "",
    "comments": "",
    "tags": [],
    "custom_fields": {},
    "created": "2023-04-23T09:32:24.766755Z",
    "last_updated": "2023-04-23T09:35:09.908879Z"
}

This is only the case if the assigned_object was not assigned before the request. Changing or removing the assigned object gives the correct response.

Originally created by @amhn on GitHub (Apr 23, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.4.8 ### Python version 3.10 ### Steps to Reproduce 1. Create IP-Address (do not assign object) 2. Create Object to assign (e.g. FHRP Group 3. `curl -H "Authorization: Token $NETBOX_TOKEN" -H "Content-type: application/json" $NETBOX_SCHEME://$NETBOX_URL/api/ipam/ip-addresses/1/ -X PATCH --data '{"assigned_object_type": "ipam.fhrpgroup", "assigned_object_id":1}'` ### Expected Behavior `assigned_object` in the response is not null. ### Observed Behavior `assigned_object` is null: ```json { "id": 1, "url": "http://localhost:8000/api/ipam/ip-addresses/1/", "display": "127.0.0.1/32", "family": { "value": 4, "label": "IPv4" }, "address": "127.0.0.1/32", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": "ipam.fhrpgroup", "assigned_object_id": 1, "assigned_object": null, "nat_inside": null, "nat_outside": [], "dns_name": "", "description": "", "comments": "", "tags": [], "custom_fields": {}, "created": "2023-04-23T09:32:24.766755Z", "last_updated": "2023-04-23T09:35:09.908879Z" } ``` This is only the case if the assigned_object was not assigned before the request. Changing or removing the assigned object gives the correct response.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:30:14 +01:00
adam closed this issue 2025-12-29 20:30:14 +01:00
Author
Owner

@arthanson commented on GitHub (May 2, 2023):

Potentially a bug in DRF / Django? we aren't doing anything special and it should be getting auto-updated, possibly related to using non-default names for the GFK fields as there have been bugs in Django related to that previously. I'll need to test it with a small sample program.

@arthanson commented on GitHub (May 2, 2023): Potentially a bug in DRF / Django? we aren't doing anything special and it should be getting auto-updated, possibly related to using non-default names for the GFK fields as there have been bugs in Django related to that previously. I'll need to test it with a small sample program.
Author
Owner

@amhn commented on GitHub (May 2, 2023):

See my previous comment https://github.com/netbox-community/netbox/issues/10221#issuecomment-1236187378 to #10221

Instead of only checking if the object exists, the patch in #11550 should have assigned it to the assigned_object field. I think.

The problem seems to be that None is None and not a None of type GFK. Once there is an object assigned to a GFK the auto update works.

@amhn commented on GitHub (May 2, 2023): See my previous comment https://github.com/netbox-community/netbox/issues/10221#issuecomment-1236187378 to #10221 Instead of only checking if the object exists, the patch in #11550 should have assigned it to the assigned_object field. I think. The problem seems to be that None is None and not a None of type GFK. Once there is an object assigned to a GFK the auto update works.
Author
Owner

@arthanson commented on GitHub (May 2, 2023):

Thanks for that, checking...

@arthanson commented on GitHub (May 2, 2023): Thanks for that, checking...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7937