Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services: added record extension registry #1781

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alejandromumo
Copy link
Member

@alejandromumo alejandromumo commented Jul 25, 2024

closes #1878


This PR introduces a new mechanism to extend the configured record class.

The idea is that some modules might want to add a single field (or method) to the record class, without polluting the core's RDM namespace.

The interface of these "extensions" is a callback that returns a valid Record class.

The extension point right now uses entry points since they can be loaded before all the extensions are initialised.

One example of a registration could be the following:

class SWHExtension(object):
    swhid = SystemField("swhid")


def add_swh_extension(app, record_cls):
    # generate a new class with the field and return it
    if current_swh_ext.is_enabled(app) and current_swh_ext.is_configured(app):
        return type(record_cls.__name__, (record_cls, SWHExtension), {})
    return record_cls

There are still unanswered questions to move forward:

  • The field can't be stored in DB or ES, if both mappings are set to strict
  • Dumpers are not extensible at the moment
  • Serializer's schemas are not extensible from config, instead, they are extensible on object initialisation. Therefore, we can't extend it from other modules than invenio-rdm-records (without subclassing the serializer entirely)

self.record_service_registry,
"invenio_rdm_records.services.record_service_registry",
)
# Discussed w/Alex
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: to be removed

new_cls = cfg_cls
for name, _ext in exts.items():
tmp = _ext(self._app, new_cls)
assert type(tmp) == type(cfg_cls), f"Invalid record type. Expected: {type(cfg_cls)}, got: {type(tmp)}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the place where the interface is being enforced

Copy link
Contributor

This PR was automatically marked as stale.

@github-actions github-actions bot added the stale label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prototype: implement record extension
1 participant