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

results: added support for drafts #1700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alejandromumo
Copy link
Member

@alejandromumo alejandromumo commented Mar 25, 2024

closes https://github.com/zenodo/ops/issues/340

  • Added support for drafts in the results list

@@ -69,3 +69,32 @@ def get_value_service(self, value):
def pick(self, identity, resolved_rec):
"""Pick fields defined in the entity resolver."""
return resolved_rec

class RDMRecordList(RecordList):
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue was that drafts are searched through the records service, which in turn uses the default RecordList class to project the search results.

The default implementation uses self._service.record_cls unconditionally, which in turn projects the result always to a record. This is not correct if the service shares the search for records and drafts. For instance, an unpublished draft always had the attribute is_draft=False because the attribute is_draft of a Record is always set to False.

* Added support for drafts in the results list
for hit in self._results:
# Load dump
record_dict = hit.to_dict()
if record_dict["is_published"]:
Copy link
Member

Choose a reason for hiding this comment

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

minor: wouldn't it be better to rely on the is_draft property? Though I think this should be a ConstantField systemfield so that it makes it to the indexed document.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's what caused the issue in the first place. the "search" method can be used for drafts or records, however, the method lives inside the record's service. So using record.is_draft always returns False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants