Incorrect Type for Device & VM local_context_data #3416

Closed
opened 2025-12-29 18:28:53 +01:00 by adam · 3 comments
Owner

Originally created by @dstarner on GitHub (Feb 26, 2020).

Originally assigned to: @dstarner on GitHub.

Environment

  • Python version: 3.7
  • NetBox version: 2.7.8

Steps to Reproduce

  1. Add config context to a device
  2. Using any generated Swagger client - we used go-netbox - try to hit one of the list routes /devices or /virtual-machines
  3. Watch the strongly-typed swagger client explode as it tries to convert a dict/map into a string

Expected Behavior

local_context_data should be defined in the Swagger documentation as either null or as an object/dict/map so that it can be handled correctly by strongly typed swagger clients.

Observed Behavior

Screen Shot 2020-02-26 at 2 12 26 PM

local_context_data is type-unaware and its converted into a string, meaning that Swagger clients will try to parse it out as a string, which will cause type errors on strongly typed systems

Originally created by @dstarner on GitHub (Feb 26, 2020). Originally assigned to: @dstarner on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7 * NetBox version: 2.7.8 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. Add config context to a device 1. Using any generated Swagger client - we used go-netbox - try to hit one of the list routes `/devices` or `/virtual-machines` 1. Watch the strongly-typed swagger client explode as it tries to convert a dict/map into a string <!-- What did you expect to happen? --> ### Expected Behavior `local_context_data` should be defined in the Swagger documentation as either `null` or as an object/dict/map so that it can be handled correctly by strongly typed swagger clients. <!-- What happened instead? --> ### Observed Behavior ![Screen Shot 2020-02-26 at 2 12 26 PM](https://user-images.githubusercontent.com/10478871/75379979-4395e800-58a4-11ea-9127-bb4850c24b74.png) `local_context_data` is type-unaware and its converted into a string, meaning that Swagger clients will try to parse it out as a string, which will cause type errors on strongly typed systems
adam added the status: acceptedtype: documentation labels 2025-12-29 18:28:53 +01:00
adam closed this issue 2025-12-29 18:28:54 +01:00
Author
Owner

@dstarner commented on GitHub (Feb 26, 2020):

Solving this would require a similar approach as what is done in the following
62efe0621f/netbox/dcim/api/serializers.py (L426-L428)

Pull it out as a serializer method and decorate it with the correct type

@dstarner commented on GitHub (Feb 26, 2020): Solving this would require a similar approach as what is done in the following https://github.com/netbox-community/netbox/blob/62efe0621f710310f9bceb46fd6d27b0d57bfb3c/netbox/dcim/api/serializers.py#L426-L428 Pull it out as a serializer method and decorate it with the correct type
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2020):

Open for volunteers.

@jeremystretch commented on GitHub (Feb 28, 2020): Open for volunteers.
Author
Owner

@dstarner commented on GitHub (Mar 2, 2020):

@jeremystretch can you assign me? I can make a PR for this. Its a pretty easy fix

@dstarner commented on GitHub (Mar 2, 2020): @jeremystretch can you assign me? I can make a PR for this. Its a pretty easy fix
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3416