IPAddress model accepts inconsistent data for GenericForeignKey "assigned_object" #7486

Closed
opened 2025-12-29 20:24:01 +01:00 by adam · 6 comments
Owner

Originally created by @moonrail on GitHub (Jan 10, 2023).

Originally assigned to: @abhi1693 on GitHub.

NetBox version

v3.4.2

Python version

3.10

Steps to Reproduce

  1. Have a Device/VM with Interface
  2. Have an IP
  3. Assign IP to Interface
  4. PATCH /ipam/ip-addresses/{id}/ and send only either assigned_object_type or assigned_object_id with value null

Expected Behavior

Request either fails with HTTP 400 and an explanation why the client sent inconsistent data or the backend sets the other attribute, that is not sent, to null/None as well.

Or - if the current behaviour is accepted - the UI does not fail with HTTP 500 'NoneType' object has no attribute 'get_absolute_url' like described in https://github.com/netbox-community/netbox/discussions/11112

Observed Behavior

Backend does exactly what the client requests and sets only the sent attribute to the value.
So now IP-Address has one assigned_object_ value referencing something and one assigned_object_ value not referencing something.

Causes this issue in the UI: https://github.com/netbox-community/netbox/discussions/11112

'NoneType' object has no attribute 'get_absolute_url'

Originally created by @moonrail on GitHub (Jan 10, 2023). Originally assigned to: @abhi1693 on GitHub. ### NetBox version v3.4.2 ### Python version 3.10 ### Steps to Reproduce 1. Have a Device/VM with Interface 2. Have an IP 3. Assign IP to Interface 4. PATCH /ipam/ip-addresses/{id}/ and send only either `assigned_object_type` or `assigned_object_id` with value `null` ### Expected Behavior Request either fails with HTTP 400 and an explanation why the client sent inconsistent data or the backend sets the other attribute, that is not sent, to null/None as well. Or - if the current behaviour is accepted - the UI does not fail with HTTP 500 `'NoneType' object has no attribute 'get_absolute_url'` like described in https://github.com/netbox-community/netbox/discussions/11112 ### Observed Behavior Backend does exactly what the client requests and sets only the sent attribute to the value. So now IP-Address has one `assigned_object_` value referencing something and one `assigned_object_` value not referencing something. Causes this issue in the UI: https://github.com/netbox-community/netbox/discussions/11112 'NoneType' object has no attribute 'get_absolute_url'
adam added the type: bugstatus: accepted labels 2025-12-29 20:24:01 +01:00
adam closed this issue 2025-12-29 20:24:01 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 10, 2023):

  1. PATCH /ipam/ip-addresses/{id}/ and send only either assigned_object_type or assigned_object_id with value null

Please share the complete API request you're sending.

@jeremystretch commented on GitHub (Jan 10, 2023): > 4. PATCH /ipam/ip-addresses/{id}/ and send only either assigned_object_type or assigned_object_id with value null Please share the complete API request you're sending.
Author
Owner

@moonrail commented on GitHub (Jan 10, 2023):

@jeremystretch
Here you go, straight from Swaggerui:

curl -X 'PATCH' \
  'https://netbox.domain.tld/api/ipam/ip-addresses/123/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFToken: XYZ' \
  -d '{
  "assigned_object_id": null
}'
@moonrail commented on GitHub (Jan 10, 2023): @jeremystretch Here you go, straight from Swaggerui: ```bash curl -X 'PATCH' \ 'https://netbox.domain.tld/api/ipam/ip-addresses/123/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFToken: XYZ' \ -d '{ "assigned_object_id": null }' ```
Author
Owner

@jeremystretch commented on GitHub (Jan 10, 2023):

This seems to overlap quite a bit with #10221. I'm not sure yet whether the fix for one will effectively resolve the other, but it's likely.

@jeremystretch commented on GitHub (Jan 10, 2023): This seems to overlap quite a bit with #10221. I'm not sure yet whether the fix for one will effectively resolve the other, but it's likely.
Author
Owner

@abhi1693 commented on GitHub (Jan 14, 2023):

@jeremystretch I'd like to take this

@abhi1693 commented on GitHub (Jan 14, 2023): @jeremystretch I'd like to take this
Author
Owner

@DanSheps commented on GitHub (Jan 20, 2023):

@abhi1693 Going to assign this to you, feel free to proceed.

@DanSheps commented on GitHub (Jan 20, 2023): @abhi1693 Going to assign this to you, feel free to proceed.
Author
Owner

@abhi1693 commented on GitHub (Jan 20, 2023):

@DanSheps Can I also get #10221? My solution fixes these both together

@abhi1693 commented on GitHub (Jan 20, 2023): @DanSheps Can I also get #10221? My solution fixes these both together
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7486