Skip to content

Commit

Permalink
serializers: fix error when no bf:Publication
Browse files Browse the repository at this point in the history
* When no `provisionActivity` of type `bf:publication` is present,
the collector returns None rather than an empty generator.
* Fixes RT 412.
* Fixes Sentry RERO-ILS-2D1.

Co-Authored-by: Pascal Repond <[email protected]>
Co-Authored-by: Renaud Michotte <[email protected]>
  • Loading branch information
PascalRepond and zannkukai committed Oct 17, 2022
1 parent 1b361ca commit 176e3f7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions rero_ils/modules/items/serializers/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ def _build_doc(data):
)
# process provision activity
provision_activity = next(
filter(lambda x: x.get('type')
== 'bf:Publication', data.get('provisionActivity'))
)
start_date = provision_activity.get('startDate', '')
end_date = provision_activity.get('endDate')
document_data['document_publication_year'] = \
f'{start_date} - {end_date}' \
if end_date else start_date

document_data['document_publisher'] = cls.separator.join(
data['value']
for stmt in provision_activity.get('statement', [])
for data in stmt.get('label', [])
if stmt['type'] == 'bf:Agent'
filter(lambda x: x.get('type') == 'bf:Publication',
data.get('provisionActivity')),
None
)
if provision_activity:
start_date = provision_activity.get('startDate', '')
end_date = provision_activity.get('endDate')
document_data['document_publication_year'] = \
f'{start_date} - {end_date}' \
if end_date else start_date

document_data['document_publisher'] = cls.separator.join(
data['value']
for stmt in provision_activity.get('statement', [])
for data in stmt.get('label', [])
if stmt['type'] == 'bf:Agent'
)
return document_data

doc_search = DocumentsSearch() \
Expand Down

0 comments on commit 176e3f7

Please sign in to comment.