Skip to content

Commit 931eeff

Browse files
committed
Merge tag '26.12.2' into develop
Improve management command
2 parents a87ded1 + e034dba commit 931eeff

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

osf/management/commands/copy_collection_submission_metadata_to_cedar.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,45 @@ def copy_collection_submission_metadata_to_cedar(dry_run=False, batch_size=100,
2323
logger.info(f'{"[DRY RUN] " if dry_run else ""}Found {total} collection submissions to process')
2424

2525
processed = errors = 0
26+
succeeded = []
27+
failed = []
2628
for submission in qs.iterator(chunk_size=batch_size):
2729
if dry_run:
2830
logger.info(f'[DRY RUN] Would sync cedar metadata for submission {submission._id}')
2931
continue
3032
try:
31-
submission.sync_cedar_metadata()
33+
record = submission.sync_cedar_metadata()
34+
succeeded.append((
35+
submission.guid._id,
36+
submission.collection._id,
37+
record._id,
38+
record.template.cedar_id,
39+
))
3240
processed += 1
3341
except Exception as e:
3442
logger.error(f'Failed to sync cedar metadata for submission {submission._id}: {e}')
43+
template = submission.collection.provider.required_metadata_template
44+
failed.append((
45+
submission.guid._id,
46+
submission.collection._id,
47+
template.cedar_id,
48+
e,
49+
))
3550
errors += 1
3651

3752
logger.info(
3853
f'{"[DRY RUN] " if dry_run else ""}'
3954
f'Done. Processed {processed}/{total} submissions'
4055
f'{f", {errors} error(s)" if errors else ""}'
4156
)
57+
if succeeded:
58+
logger.info('Successfully synced (node_guid, collection_id, cedar_record_id, cedar_template_id):')
59+
for node_guid, collection_id, record_id, template_cedar_id in succeeded:
60+
logger.info(f' node={node_guid}, collection={collection_id}, record={record_id}, template={template_cedar_id}')
61+
if failed:
62+
logger.info('Failed (node_guid, collection_id, cedar_template_id):')
63+
for node_guid, collection_id, template_cedar_id, exc in failed:
64+
logger.info(f' node={node_guid}, collection={collection_id}, template={template_cedar_id}, error={exc}')
4265

4366

4467
class Command(BaseCommand):

osf/models/collection_submission.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,15 @@ def sync_cedar_metadata(self):
524524
from osf.models.cedar_metadata import CedarMetadataRecord
525525
template = self.collection.provider.required_metadata_template
526526
metadata = {}
527+
# Some ibdgc collection projects lacks values on some metadata fields; use "N/A" as a placeholder for missing values.
528+
ibdgc_provider = self.collection.provider._id == 'ibdgc'
527529
for field in self.CEDAR_METADATA_FIELDS:
528530
value = getattr(self, field)
529531
if not value:
530-
continue
532+
if ibdgc_provider:
533+
value = 'N/A' # ibdgc: populate missing fields rather than omitting them
534+
else:
535+
continue
531536
entry = _cedar_record_field_entry(template.template, field, value)
532537
if entry is None:
533538
logger.warning(f'No CEDAR property matches field "{field}" on template "{template.schema_name}"')
@@ -544,6 +549,7 @@ def sync_cedar_metadata(self):
544549
record.metadata = metadata
545550
record.is_published = True
546551
record.save()
552+
return record
547553

548554
def save(self, *args, **kwargs):
549555
ret = super().save(*args, **kwargs)

0 commit comments

Comments
 (0)