Skip to content

[config] Merging lists #153

Open
openwisp/openwisp-controller
#814

Description

@nemesifier

The way configuration is merged with templates now has a quirk:
list elements from different templates are merged with the config.

This is needed for list of objects (eg: interfaces, routes), but it's weird and has caused misunderstanding among users when they try to override list options.

I still haven't come up with an optimal solution.

Activity

  1. added
    Hacktoberfest
    and removed
    Hacktoberfest
    on Sep 30, 2020
  2. okraits commented on Jun 16, 2023

    @okraits
    Member

    Let's list the options we have so we can get closer to a solution.

    1. Items of lists with the same name in different templates are merged, resulting in a list containing all items from all templates. This is the current behaviour.
    2. If there are lists with the same name in different templates, the items of the list in the template with the highest priority will be the items in the resulting list, overriding the items in the other templates. This has the disadvantage that for adding items to a list, all common items need to be listed in several templates.
    3. We could add an option/setting to the list in our templates which defines the behaviour of that list if there is a list with the same name in a template with lower priority: add items to that lower priority list or replace items. This makes it possible to choose the behaviour depending on the usecase.

    @nemesisdesign What do you think?

  3. nemesifier commented on Jun 16, 2023

    @nemesifier
    MemberAuthor

    @okraits option 3. sounds like a good idea, an "advanced option" which allows to decide if the user wants to add to any previous template or override, to be set on a per template basis and it would act only on previous templates, right?

  4. okraits commented on Jun 19, 2023

    @okraits
    Member

    @okraits option 3. sounds like a good idea, an "advanced option" which allows to decide if the user wants to add to any previous template or override, to be set on a per template basis and it would act only on previous templates, right?

    Yes, each template would basically take the result of the previous templates as input and then override that or add to it, based on the selected advanced option.

  5. okraits commented on Sep 14, 2023

    @okraits
    Member

    @nemesifier So if you're ok with option 3, I will start to work on it, ok?

  6. nemesifier commented on Sep 14, 2023

    @nemesifier
    MemberAuthor

    @okraits how do you intend to implement this? Are we going to add an initialization argument to the library?

    You mention adding an "option" to the list, can you expand on this?

  7. okraits commented on Sep 14, 2023

    @okraits
    Member

    @okraits how do you intend to implement this? Are we going to add an initialization argument to the library?

    You mention adding an "option" to the list, can you expand on this?

    @nemesifier

    To be honest, I have to look into the code first to see what's possible. I'll get back to you with a proposal, ok?

  8. okraits commented on Oct 16, 2023

    @okraits
    Member

    @nemesifier I thought about the whole topic and possible solutions.

    Originally I thought about adding a "meta setting" to every list in the json configuration dictionary (which would mean that we would have to store a list in json in a surrounding dictionary to be able to have a "meta setting") to define wether the corresponding list should be merged with or override an existing list.
    But I guess that this is too complex, we would need to extend the json schema and possibly modify all the parsers, converters and renderers.

    So I guess the more simple solution is to add a field to the AbstractTemplate model to define the behaviour of lists for each template. I can think of the following behaviours:

    • override/replace an existing list
    • insert items at the beginning of an existing list
    • append items to the end of an existing list

    Am I correct that we basically need to modify the following functions to implement the behaviours mentioned above:

    What do you think?

  9. okraits commented on Oct 23, 2023

    @okraits
    Member

    @nemesifier Any opinion on my suggestion?

  10. added a commit that references this issue on Nov 9, 2023
    242853a
  11. okraits commented on Nov 9, 2023

    @okraits
    Member

    @nemesifier I didn't receive a response from you, so I implemented this. Please take a look at it and feel free to ask questions or request changes.

    P.S. I will first wait for your feedback and fix the tests afterwards.

  12. moved this to To do (Device management) in Roadmapon Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      To do (Device management)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions