Skip to content

[feature] Make register_menu_group(item) idempotent #641

@asmodehn

Description

@asmodehn

Is your feature request related to a problem? Please describe.

When attempting to use django.test.override_settings(<INSTALLED_APPS>) in tests, it fails.

django.core.exceptions.ImproperlyConfigured: A group/link with config {...} is being registered at position "40",                but another group named "Users & Organizations" is already registered at the same position.

The current problem is that the application is reinitialized (ready called a second time), and register_menu_group fails, since it is already there at the specific location.

Describe the solution you'd like
Ideally, register_menu_group(item) should be idempotent, so calling it multiple times would just ensure it worked. Not crash with an error, when everything is actually in place in the menu.

The simple way to achieve this seems to be skipping the error, if it is the exact same item which is already there, that is being registered again. Just replacing it with the new one (in case the old one is broken for some reason known to the user calling register_menu_group)

Additional context
I seem to remember I already encountered this problem in the past, and there was an issue somewhere... Can't find it now though, and I am hitting this problem again on openwisp modules v1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions