Return nested representations of related objects when modifying an object via the API #1474

Closed
opened 2025-12-29 16:32:22 +01:00 by adam · 1 comment
Owner

Originally created by @cimnine on GitHub (Dec 22, 2017).

Issue type

[ ] Feature request
[X] Bug report
[ ] Documentation

Environment

  • Python version: 3.6
  • NetBox version: 2.2.8

Description

When I request virtual interfaces, the virtual_machine field is expanded to include the VM's details.
But when I PATCH a virtual interface, the virtual_machine field is simply the id of the VM.

GET http://netbox-frontend.ninevirt.docker/api/virtualization/interfaces/13/:

{
    "id": 13,
    "name": "eth0",
    "virtual_machine": {
        "id": 4,
        "url": "http://netbox-frontend.ninevirt.docker/api/virtualization/virtual-machines/4/",
        "name": "development-root-v3-xenial"
    },
    "enabled": true,
    "mac_address": "52:54:00:B5:BC:74",
    "mtu": null,
    "description": ""
}

PATCH http://netbox-frontend.ninevirt.docker/api/virtualization/interfaces/13/:

{
    "id": 13,
    "name": "eth0",
    "virtual_machine": 4,
    "enabled": true,
    "mac_address": "52:54:00:B5:BC:74",
    "mtu": null,
    "description": ""
}
Originally created by @cimnine on GitHub (Dec 22, 2017). <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. For assistance with installation issues, or for any other issues other than those listed below, please raise your topic for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. Due to an excessive backlog of feature requests, we are not currently accepting any proposals which extend NetBox's feature scope. Do not prepend any sort of tag to your issue's title. An administrator will review your issue and assign labels as appropriate. ---> ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [X] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Python version: 3.6 * NetBox version: 2.2.8 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description When I request virtual interfaces, the `virtual_machine` field is expanded to include the VM's details. But when I PATCH a virtual interface, the `virtual_machine` field is simply the id of the VM. **GET http://netbox-frontend.ninevirt.docker/api/virtualization/interfaces/13/:** ``` { "id": 13, "name": "eth0", "virtual_machine": { "id": 4, "url": "http://netbox-frontend.ninevirt.docker/api/virtualization/virtual-machines/4/", "name": "development-root-v3-xenial" }, "enabled": true, "mac_address": "52:54:00:B5:BC:74", "mtu": null, "description": "" } ``` **PATCH http://netbox-frontend.ninevirt.docker/api/virtualization/interfaces/13/:** ``` { "id": 13, "name": "eth0", "virtual_machine": 4, "enabled": true, "mac_address": "52:54:00:B5:BC:74", "mtu": null, "description": "" } ```
adam added the status: acceptedtype: feature labels 2025-12-29 16:32:22 +01:00
adam closed this issue 2025-12-29 16:32:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 26, 2017):

This happens because we're using separate read and write serializers for most endpoints. (The write serializer allows for setting related fields using only a primary key, whereas the read serializer returns a nested representation of the related object.) I'd love to consolidate these functions into a single serializer for each object, but haven't found a practical way to do so yet.

@jeremystretch commented on GitHub (Dec 26, 2017): This happens because we're using separate read and write serializers for most endpoints. (The write serializer allows for setting related fields using only a primary key, whereas the read serializer returns a nested representation of the related object.) I'd love to consolidate these functions into a single serializer for each object, but haven't found a practical way to do so yet.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1474