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

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

Closed
cimnine opened this issue Dec 22, 2017 · 1 comment
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@cimnine
Copy link
Contributor

cimnine commented 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": ""
}
cimnine added a commit to ninech/netbox-client-ruby that referenced this issue Dec 22, 2017
In [some special cases][1794] the `raw_data` is just the id of
the VM rather than an expanded object. This is a workaround, so
that the usual experience stays the same in that case.

[1794]: netbox-community/netbox#1794
@jeremystretch
Copy link
Member

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 jeremystretch added the type: feature Introduction of new functionality to the application label Dec 26, 2017
@jeremystretch jeremystretch changed the title PUT response doesn't match GET response for Virtual Interfaces Return nested representations of related objects when modifying an object via the API Dec 26, 2017
@jeremystretch jeremystretch added this to the v2.4 milestone Jan 26, 2018
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation API change labels Jan 26, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants