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

Config context merging of objects #5698

Closed
jchmielniak opened this issue Jan 27, 2021 · 1 comment
Closed

Config context merging of objects #5698

jchmielniak opened this issue Jan 27, 2021 · 1 comment
Labels
status: under review Further discussion is needed to determine this issue's scope and/or implementation

Comments

@jchmielniak
Copy link

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

@DanSheps DanSheps added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Feb 1, 2021
@jeremystretch
Copy link
Member

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: under review Further discussion is needed to determine this issue's scope and/or implementation
Projects
None yet
Development

No branches or pull requests

3 participants