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

Allow Plugins to register a list of Django apps to be appended to INSTALLED_APPS #9880

Closed
jsenecal opened this issue Jul 29, 2022 · 6 comments · Fixed by #10502
Closed

Allow Plugins to register a list of Django apps to be appended to INSTALLED_APPS #9880

jsenecal opened this issue Jul 29, 2022 · 6 comments · Fixed by #10502
Assignees
Labels
status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Milestone

Comments

@jsenecal
Copy link
Contributor

jsenecal commented Jul 29, 2022

NetBox version

v3.4

Feature type

New functionality

Proposed functionality

As discussed in #5086 (closed due to inactivity) it would be nice to allow for a plugin to append third-party Django Application into INSTALLED_APPS.

Borrowing from the issue above, the proposal is to extend the PluginConfig class to support a new django_apps attribute which would get appended to INSTALLED_APPS.

from extras.plugins import PluginConfig

class FooBarConfig(PluginConfig):
    name = 'foo_bar'
    verbose_name = 'Foo Bar'
    description = 'An example NetBox plugin'
    version = '0.1'
    author = 'Jeremy Stretch'
    author_email = '[email protected]'
    base_url = 'foo-bar'
    required_settings = []
    default_settings = {
        'baz': True
    }
    django_apps = ["foo", "bar", "baz"] ### <<< HERE

config = FooBarConfig

These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts.

The documentation should point out that additional apps may cause more harm than good and could lead to make identifying problems within NetBox itself more difficult or even cause problems. (But isn't that the case for every python package?)

Use case

When working with plugins, reusing third party libraries is a must to promote code re-use and allow for better functionality and ease of use.
Examples of that are apps that introduce new field types (with template tags), new templates, new models with migrations, new manage.py admin commands, etc. Most of the time, simply installing the python package for the additional app is simply not enough.

There are many existing Django apps that could be easily reused/extended within NetBox if we could seamlessly install them from a plugin.

Database changes

None within NetBox

External dependencies

None within NetBox

@jsenecal jsenecal added the type: feature Introduction of new functionality to the application label Jul 29, 2022
@jsenecal
Copy link
Contributor Author

This can be assigned to me and I can work on a PR if accepted.

@jeremystretch
Copy link
Member

jeremystretch commented Aug 1, 2022

One thing to consider is the order in which apps are loaded. I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list django_rq after our extras app to ensure that we can override one of the management commands it provides.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Aug 1, 2022
@jeremystretch jeremystretch changed the title Allow Plugins register a list of Django apps to be appended to INSTALLED_APPS Allow Plugins to register a list of Django apps to be appended to INSTALLED_APPS Aug 1, 2022
@jeremystretch jeremystretch added the topic: plugins Relates to the plugins framework label Aug 1, 2022
@jsenecal
Copy link
Contributor Author

jsenecal commented Aug 2, 2022

One thing to consider is the order in which apps are loaded. I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list django_rq after our extras app to ensure that we can override one of the management commands it provides.

As mentioned in the Proposed functionality section above:

These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts.

Are you requesting for the ability to do the opposite ?

@jeremystretch
Copy link
Member

I'm pointing out that it needs to be considered because there are scenarios where it may be required, such as the example I cited.

@jsenecal
Copy link
Contributor Author

jsenecal commented Aug 2, 2022

In that case we may consider the order of the list django_apps as important when the plugin name itself is in the list.
like so:

django_apps = ["foo", "bar", "my_netbox_plugin", "baz"]

If "my_netbox_plugin" is not in the list, we append it to the end automatically for convenience.

This would in turn define the import order for the apps and plugin.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Aug 24, 2022
@jeremystretch jeremystretch added this to the v3.4 milestone Aug 24, 2022
@jeremystretch
Copy link
Member

Thinking about this further, I can't come up with a scenario where you would need to load another Django app after a plugin which depends on it, so maybe it doesn't matter so long as the dependencies are loaded before all plugins.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Projects
None yet
2 participants