From c4a92c428b42ed8bd2cc860ac583a71b0ed51f81 Mon Sep 17 00:00:00 2001 From: Alef Burzmali Date: Wed, 28 Dec 2022 19:49:06 +0100 Subject: [PATCH 1/2] Fixes #11223 - Accept app_label for reindex --- netbox/extras/management/commands/reindex.py | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/netbox/extras/management/commands/reindex.py b/netbox/extras/management/commands/reindex.py index f519688f830..b601a1ac1cd 100644 --- a/netbox/extras/management/commands/reindex.py +++ b/netbox/extras/management/commands/reindex.py @@ -27,17 +27,28 @@ def _get_indexers(self, *model_names): # Return only indexers for the specified models else: for label in model_names: - try: - app_label, model_name = label.lower().split('.') - except ValueError: + labels = label.lower().split('.') + + # Label specifies an exact model + if len(labels) == 2: + app_label, model_name = labels + try: + idx = registry['search'][f'{app_label}.{model_name}'] + indexers[idx.model] = idx + except KeyError: + raise CommandError(f"No indexer registered for {label}") + + # Label specifies all the models of an app + elif len(labels) == 1: + app_label = labels[0] + '.' + for indexer_label, idx in registry['search'].items(): + if indexer_label.startswith(app_label): + indexers[idx.model] = idx + + else: raise CommandError( - f"Invalid model: {label}. Model names must be in the format .." + f"Invalid model: {label}. Model names must be in the format or .." ) - try: - idx = registry['search'][f'{app_label}.{model_name}'] - indexers[idx.model] = idx - except KeyError: - raise CommandError(f"No indexer registered for {label}") return indexers From cb7905c1ae3cb13ad791550c90bd87165ae6603b Mon Sep 17 00:00:00 2001 From: Alef Burzmali Date: Wed, 28 Dec 2022 21:06:11 +0100 Subject: [PATCH 2/2] Fixes #11248 - Reindex only NetBox apps --- netbox/extras/migrations/0083_search.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netbox/extras/migrations/0083_search.py b/netbox/extras/migrations/0083_search.py index 8f67717bbf0..0c53de638c2 100644 --- a/netbox/extras/migrations/0083_search.py +++ b/netbox/extras/migrations/0083_search.py @@ -10,7 +10,16 @@ def reindex(apps, schema_editor): # Build the search index (except during tests) if 'test' not in sys.argv: - management.call_command('reindex') + management.call_command( + 'reindex', + 'circuits', + 'dcim', + 'extras', + 'ipam', + 'tenancy', + 'virtualization', + 'wireless', + ) class Migration(migrations.Migration):