Skip to content

Commit

Permalink
Merge pull request #83 from oarepo/miroslavsimek/be-69-invenio-oarepo…
Browse files Browse the repository at this point in the history
…-index-reindex-fails-on-services-that-have-no

Fixed potential non-existent record classes on service config
  • Loading branch information
mesemus authored Jul 28, 2023
2 parents 26595b3 + 4afe63b commit 3ce986f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions oarepo_runtime/cli/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,29 @@ def _build(tree_or_filename, alias=None):


def record_or_service(model):
# TODO: is this still used (maybe from somewhere else?)
try:
service = current_service_registry.get(model)
except KeyError:
service = None
if service:
record = service.config.record_cls
if service and getattr(service, 'config', None):
record = getattr(service.config, 'record_cls', None)
else:
try:
record = import_string(model)
except ImportStringError:
click.secho(
"Service or model not found. Known services: ",
fg="red",
bold=True,
file=sys.stderr,
)
for svc in sorted(current_service_registry._services):
click.secho(f" {svc}", file=sys.stderr)
sys.exit(1)
record=None

if record is None:
click.secho(
"Service or model not found. Known services: ",
fg="red",
bold=True,
file=sys.stderr,
)
for svc in sorted(current_service_registry._services):
click.secho(f" {svc}", file=sys.stderr)
sys.exit(1)
return record


Expand All @@ -93,9 +97,9 @@ def reindex(model):
click.secho(f"Preparing to index {service_id}", file=sys.stderr)

service = current_service_registry.get(service_id)
record_class = service.config.record_cls
record_class = getattr(service.config, 'record_cls', None)

if not hasattr(service, "indexer"):
if not record_class or not hasattr(service, "indexer"):
continue

try:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-runtime
version = 1.3.22
version = 1.3.23
description = A set of runtime extensions of Invenio repository
authors = Alzbeta Pokorna
readme = README.md
Expand Down

0 comments on commit 3ce986f

Please sign in to comment.