Skip to content

Reindex command does not accept app_label as argument #11223

@Alef-Burzmali

Description

@Alef-Burzmali

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.

for label in model_names:
try:
app_label, model_name = label.lower().split('.')
except ValueError:
raise CommandError(
f"Invalid model: {label}. Model names must be in the format <app_label>.<model_name>."
)
try:
idx = registry['search'][f'{app_label}.{model_name}']
indexers[idx.model] = idx
except KeyError:
raise CommandError(f"No indexer registered for {label}")

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions