Reindex command does not accept app_label as argument #7378

Closed
opened 2025-12-29 20:22:38 +01:00 by adam · 2 comments
Owner

Originally created by @Alef-Burzmali on GitHub (Dec 17, 2022).

Originally assigned to: @Alef-Burzmali on GitHub.

NetBox version

v3.4.1

Python version

3.10

Steps to Reproduce

  1. Look at the help of the reindex management command: it accepts app_label[.ModelName]
$ python /opt/netbox/netbox/manage.py reindex -h
[...]
positional arguments:
  app_label[.ModelName]
                        One or more apps or models to reindex
  1. Reindex all models of a plugin or an app:
$ python /opt/netbox/netbox/manage.py reindex dcim
CommandError: Invalid model: dcim. Model names must be in the format <app_label>.<model_name>.

The use case is reindexing all the models of a plugin after adding SearchIndex for my models.

Expected Behavior

The command reindexes all the the models of the plugin/app corresponding to app_label.

Observed Behavior

CommandError: Invalid model: dcim. Model names must be in the format <app_label>.<model_name>.

The current code does not allow selecting all the models of an app. registry['search'] could be iterated to find all the models of the app if there is no dot in model_names, or simpler, the args of the command could be updated to remove that possibility.

3675ad2539/netbox/extras/management/commands/reindex.py (L29-L40)

Originally created by @Alef-Burzmali on GitHub (Dec 17, 2022). Originally assigned to: @Alef-Burzmali on GitHub. ### NetBox version v3.4.1 ### Python version 3.10 ### Steps to Reproduce 1. Look at the help of the reindex management command: it accepts ```app_label[.ModelName]``` ``` $ python /opt/netbox/netbox/manage.py reindex -h [...] positional arguments: app_label[.ModelName] One or more apps or models to reindex ``` 2. Reindex all models of a plugin or an app: ``` $ python /opt/netbox/netbox/manage.py reindex dcim CommandError: Invalid model: dcim. Model names must be in the format <app_label>.<model_name>. ``` The use case is reindexing all the models of a plugin after adding SearchIndex for my models. ### Expected Behavior The command reindexes all the the models of the plugin/app corresponding to app_label. ### Observed Behavior ``` CommandError: Invalid model: dcim. Model names must be in the format <app_label>.<model_name>. ``` The current code does not allow selecting all the models of an app. ```registry['search']``` could be iterated to find all the models of the app if there is no dot in model_names, or simpler, the args of the command could be updated to remove that possibility. https://github.com/netbox-community/netbox/blob/3675ad2539400038af6797140ddca3679b8bca30/netbox/extras/management/commands/reindex.py#L29-L40
adam added the type: bugstatus: accepted labels 2025-12-29 20:22:38 +01:00
adam closed this issue 2025-12-29 20:22:38 +01:00
Author
Owner

@Alef-Burzmali commented on GitHub (Dec 28, 2022):

Thanks for accepting the bug. Would you please assign it to me so I can make a PR?

I think it can be used to address #11248 too, if the migration extras.0083_search is modified to reindex only the apps of NetBox core. Then, plugin authors will have to add a small migration like 0083_search for their own models, but I guess it will always be required when new SearchIndexes are added. Please let me know if I should tackle that one too.

@Alef-Burzmali commented on GitHub (Dec 28, 2022): Thanks for accepting the bug. Would you please assign it to me so I can make a PR? I think it can be used to address #11248 too, if the migration extras.0083_search is modified to reindex only the apps of NetBox core. Then, plugin authors will have to add a small migration like 0083_search for their own models, but I guess it will always be required when new SearchIndexes are added. Please let me know if I should tackle that one too.
Author
Owner

@kkthxbye-code commented on GitHub (Dec 28, 2022):

@Alef-Burzmali - All yours

@kkthxbye-code commented on GitHub (Dec 28, 2022): @Alef-Burzmali - All yours
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7378