Config context merging of objects #4506

Closed
opened 2025-12-29 18:36:49 +01:00 by adam · 1 comment
Owner

Originally created by @jchmielniak on GitHub (Jan 27, 2021).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.10.3

Proposed Functionality

Cnfig contex are being merged as defined in documentation. Context with higher weight overwrites the lower.
This works good for contexts with simple JSON values. With object and list this behavior is not consistent.
JSON List follows merging like variables and JSON object are being merged to a new object including keys from both context.
This is w very practical but not documented feature. It would be good if lists could use the same merging schema.
We use merging of objects to add some additional items for a group of devices.
Fe: We set 2 DNS Server in Region, but for some devices we add a third one.

I am not sure it is a bug or feature.

Use Case

Functionality now:
Context A
{
"list": ["1", "2"],
"obj": {"one": "this"}
}
Context B
{
"list": ["10", "20"],
"obj": {"two": "that"}
}

Resulting context:
{
"list": ["1", "2"],
"obj": {
"one": "this",
"two": "that"
}
}

Expected context:
{
"list": ["1", "2", "10", "20"],
"obj": {
"one": "this",
"two": "that"
}
}

Database Changes

External Dependencies

Originally created by @jchmielniak on GitHub (Jan 27, 2021). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. 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.6.8 * NetBox version: 2.10.3 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Cnfig contex are being merged as defined in documentation. Context with higher weight overwrites the lower. This works good for contexts with simple JSON values. With object and list this behavior is not consistent. JSON List follows merging like variables and JSON object are being merged to a new object including keys from both context. This is w very practical but not documented feature. It would be good if lists could use the same merging schema. We use merging of objects to add some additional items for a group of devices. Fe: We set 2 DNS Server in Region, but for some devices we add a third one. I am not sure it is a bug or feature. <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Functionality now: Context A { "list": ["1", "2"], "obj": {"one": "this"} } Context B { "list": ["10", "20"], "obj": {"two": "that"} } Resulting context: { "list": ["1", "2"], "obj": { "one": "this", "two": "that" } } Expected context: { "list": ["1", "2", "10", "20"], "obj": { "one": "this", "two": "that" } } <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies
adam added the status: under review label 2025-12-29 18:36:49 +01:00
adam closed this issue 2025-12-29 18:36:49 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 4, 2021):

With object and list this behavior is not consistent.

The behavior is consistent, it's just not what you want. Each key within a higher-weight ConfigContext will overwrite the same key (if any) in a lower-weight ConfigContext, regardless of value type. This is by design, and allows us to reliably overwrite lists or dictionaries as needed. (For example, setting a global list of NTP servers, and overwriting it with a region-specific list.) Changing this would break the current behavior.

@jeremystretch commented on GitHub (Feb 4, 2021): > With object and list this behavior is not consistent. The behavior _is_ consistent, it's just not what you want. Each key within a higher-weight ConfigContext will overwrite the same key (if any) in a lower-weight ConfigContext, regardless of value type. This is by design, and allows us to reliably overwrite lists or dictionaries as needed. (For example, setting a global list of NTP servers, and overwriting it with a region-specific list.) Changing this would break the current behavior.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4506