Include a data model in the repository's global (cross-model) search.
Repositories can host several different kinds of records (models),
e.g. "datasets" and "publications". Call this once per model package
to make its records show up in searches that span all models at
once (as opposed to searching within just one model). This does not
register the model itself (its API endpoints, forms, etc.) - that is
normally done separately, by calling that model package's own
register() function.
Parameters:
| Name |
Type |
Description |
Default |
model_package_name
|
str
|
The Python import path of the generated
model package to add, e.g. "datasets" for a model built
from a datasets model package. If the package cannot be
found or has not been built yet, this is only logged as an
error - it does not stop the repository from starting.
|
required
|
Invenio configuration variables set:
GLOBAL_SEARCH_MODELS - the model's MODEL_DEFINITION is
appended to this list; any models already registered (by earlier
calls, or by other packages) are kept.
Example
from datasets import datasets_model
datasets_model.register()
config.add_model("datasets")
Source code in oarepo_config/models.py
| def add_model(model_package_name: str) -> None:
"""Include a data model in the repository's global (cross-model) search.
Repositories can host several different kinds of records (models),
e.g. "datasets" and "publications". Call this once per model package
to make its records show up in searches that span all models at
once (as opposed to searching within just one model). This does not
register the model itself (its API endpoints, forms, etc.) - that is
normally done separately, by calling that model package's own
`register()` function.
Args:
model_package_name: The Python import path of the generated
model package to add, e.g. `"datasets"` for a model built
from a `datasets` model package. If the package cannot be
found or has not been built yet, this is only logged as an
error - it does not stop the repository from starting.
Invenio configuration variables set:
* `GLOBAL_SEARCH_MODELS` - the model's `MODEL_DEFINITION` is
appended to this list; any models already registered (by earlier
calls, or by other packages) are kept.
Example:
```python
from datasets import datasets_model
datasets_model.register()
config.add_model("datasets")
```
"""
from invenio_base.utils import obj_or_import_string
model = obj_or_import_string(f"runtime_models_{model_package_name}")
if hasattr(model, "record_error_handlers"):
RDM_RECORDS_ERROR_HANDLERS = (
get_constant_from_caller("RDM_RECORDS_ERROR_HANDLERS") | model.record_error_handlers # type: ignore[reportOptionalMemberAccess]
)
set_constants_in_caller({"RDM_RECORDS_ERROR_HANDLERS": RDM_RECORDS_ERROR_HANDLERS})
|