8000 Property Setters don't deduplicate in dict or list case · Issue #3211 · cobbler/cobbler · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Property Setters don't deduplicate in dict or list case #3211

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

Closed
SchoolGuy opened this issue Jul 25, 2022 · 2 comments · Fixed by #3252
Closed

Property Setters don't deduplicate in dict or list case #3211

SchoolGuy opened this issue Jul 25, 2022 · 2 comments · Fixed by #3252
Assignees
Labels
Bug Report Reporting a bug main Not a release but referring to the Git main branch
Milestone

Comments

@SchoolGuy
Copy link
Member

Describe the bug

When using a setter like item.kernel_options, the setter is assuming that you pass it a raw value. However if the data is retrieved before via item.kernel_options the data returned is resolved. This leads to data duplication inside Cobbler.

Steps to reproduce

  1. my_value = item.kernel_options
  2. Do things with my_value
  3. item.kernel_options = my_value

Expected behavior

The data that is attached to the parent(s) is not duplicated in the children.

Cobbler version

Operating system

Cobbler log

Screenshots

Additional information

This can be fixed with logic that is already present in CobblerAPI.set_item_resolved_value.

@SchoolGuy SchoolGuy added the Bug Report Reporting a bug label Jul 25, 2022
@SchoolGuy SchoolGuy added this to the v3.4.0 milestone Jul 25, 2022
@SchoolGuy SchoolGuy moved this to Todo in Cobbler Server Jul 25, 2022
@SchoolGuy SchoolGuy added the main Not a release but referring to the Git main branch label Aug 3, 2022
@SchoolGuy SchoolGuy linked a pull request Aug 3, 2022 that will close this issue
@SchoolGuy SchoolGuy moved this from Todo to In Progress in Cobbler Server Aug 3, 2022
@SchoolGuy SchoolGuy self-assigned this Dec 4, 2022
@SchoolGuy
Copy link
Member Author

So since the linked PR shows that this problem is more complex than I thought, I will write down the problem to find a solution hopefully.

Problem: When utilizing setters in our items it can happen that "raw" values contain duplicated content. This may lead to problems with retrieving the correct resolved value.

Data types that are affected by this:

  • str: Not a problem since we have the strategy of "last-one-wins".
  • int: Same as str.
  • float: Same as str.
  • bool: Same as str.
  • enum.Enum: Same as str.
  • list: We inherit this implicitly. Affected by this bug.
  • dict: We inherit this implicitly. Affected by this bug.

Tackling the first problem: list

Inheritance with list works that we combine all the lists from all raw item values. This is a recursive operation. We have no special syntax that removes entries (in contract to dict). We also don't have a way to keep track of the order things are blended together.

The keys that are of type list atm don't depend on the order of the entries in a list and as such this is not a big problem. To deduplicate this correctly we just ask the parent object for its resolved value and remove all those entries in our list. The resulting list must be our new raw value. This behaviour can be easily ensured via testing.

Tackling the second problem: dict

Inheritance with dict works that we combine all the dicts from all the raw items. This is a recursive operation. We do want to remove keys in our dict that start with an exclamation mark. We don't have a way to keep track of the order of things are blended together.

Since the blended dict doesn't contain the key removals via the exclamation mark anymore this operation is a bit harder. Furthermore, values may be overridden by children. Atm we cannot handle correctly that a key is mentioned multiple times but so far it seems that this is not required by users (even though it may happen in the kernel options that this is needed).

Furthermore, it is unintuitive that users cannot directly update the dictionary that is returned to them via the property. I think this should be an orthogonal problem.

Using the strategy from the list we gain a good approximation of what we want but it could be that it doesn't work as desired.

Intermediate result of my thoughts: It seems that somewhere in this thought process I have a logic error because that is precisely what was implemented in the linked PR. However, the testsuite is showing me a lot of errors that I cannot explain myself atm.

@SchoolGuy
Copy link
Member Author
SchoolGuy commented Dec 15, 2023

After fixing the bug in the linked PR I discovered that it appears that the only inheritance that the list type does is if it is set to <<inherit>>. If there is any other value then it stays as-is. Which limits the bugfix to a much smaller scope.

This smaller scope means that no deduplication for lists needs to be performed and resolving them only is done with a value takeover.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Cobbler Server Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Reporting a bug main Not a release but referring to the Git main branch
Projects
Status: Done
1 participant
0