-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
status: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Description
NetBox version
v3.4.1
Python version
3.10
Steps to Reproduce
- 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
- 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.
netbox/netbox/extras/management/commands/reindex.py
Lines 29 to 40 in 3675ad2
| 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 implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application