Skip to content

Commit 494df5b

Browse files
committed
Merge branch 'hotfix/25.07.1'
2 parents 6aef55d + 3d7d244 commit 494df5b

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

api/crossref/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from framework.auth.views import mails
1010
from osf.models import Preprint
1111
from website import settings
12+
from website.preprints.tasks import mint_doi_on_crossref_fail
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -66,8 +67,7 @@ def post(self, request):
6667
elif record.get('status').lower() == 'failure':
6768
if 'Relation target DOI does not exist' in record.find('msg').text:
6869
logger.warning('Related publication DOI does not exist, sending metadata again without it...')
69-
client = preprint.get_doi_client()
70-
client.create_identifier(preprint, category='doi', include_relation=False)
70+
mint_doi_on_crossref_fail.apply_async(kwargs={'preprint_id': preprint._id})
7171
# This error occurs when a single preprint is being updated several times in a row with the same metadata [#PLAT-944]
7272
elif 'less or equal to previously submitted version' in record.find('msg').text and record_count == 2:
7373
break
@@ -78,12 +78,13 @@ def post(self, request):
7878
if dois_processed != record_count or status != 'completed':
7979
if unexpected_errors:
8080
batch_id = crossref_email_content.find('batch_id').text
81+
email_error_text = request.POST['body-plain']
8182
mails.send_mail(
8283
to_addr=settings.OSF_SUPPORT_EMAIL,
8384
mail=mails.CROSSREF_ERROR,
8485
batch_id=batch_id,
85-
email_content=request.POST['body-plain'],
86+
email_content=email_error_text,
8687
)
87-
logger.error(f'Error submitting metadata for batch_id {batch_id} with CrossRef, email sent to help desk')
88+
logger.error(f'Error submitting metadata for batch_id {batch_id} with CrossRef, email sent to help desk: {email_error_text}')
8889

8990
return HttpResponse('Mail received', status=200)

website/identifiers/clients/crossref.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,19 @@ def build_posted_content(self, preprint, element, include_relation):
140140
for preprint_version, previous_version in zip(preprint_versions, preprint_versions[1:]):
141141
if preprint_version.version > preprint.version:
142142
continue
143+
144+
minted_doi = previous_version.get_identifier_value('doi')
145+
if not minted_doi:
146+
previous_doi = self.build_doi(previous_version)
147+
143148
related_item = element.related_item(
144149
element.intra_work_relation(
145-
self.build_doi(previous_version),
150+
minted_doi or previous_doi,
146151
**{'relationship-type': 'isVersionOf', 'identifier-type': 'doi'}
147152
)
148153
)
149154
relations_program.append(related_item)
155+
150156
if len(relations_program) > 0:
151157
posted_content.append(relations_program)
152158

website/preprints/tasks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from framework.postcommit_tasks.handlers import enqueue_postcommit_task, get_task_from_postcommit_queue
77

88

9+
CROSSREF_FAIL_RETRY_DELAY = 12 * 60 * 60
910
logger = logging.getLogger(__name__)
1011

1112

@@ -62,3 +63,24 @@ def update_or_enqueue_on_preprint_updated(preprint_id, saved_fields=None):
6263
},
6364
celery=True
6465
)
66+
67+
68+
@celery_app.task(bind=True, acks_late=True, max_retries=5, default_retry_delay=CROSSREF_FAIL_RETRY_DELAY)
69+
def mint_doi_on_crossref_fail(self, preprint_id):
70+
from osf.models import Preprint
71+
preprint = Preprint.load(preprint_id)
72+
existing_versions_without_minted_doi = Preprint.objects.filter(
73+
versioned_guids__guid=preprint.versioned_guids.first().guid,
74+
versioned_guids__version__lt=preprint.versioned_guids.first().version,
75+
preprint_doi_created__isnull=True
76+
).exclude(id=preprint.id)
77+
if existing_versions_without_minted_doi:
78+
logger.error(
79+
f'There are existing preprint versions for preprint with guid {preprint._id} that are missing DOIs. Versions: '
80+
f'{list(existing_versions_without_minted_doi.values_list('versioned_guids__version', flat=True))}'
81+
)
82+
self.retry()
83+
else:
84+
crossref_client = preprint.get_doi_client()
85+
if crossref_client:
86+
crossref_client.create_identifier(preprint, category='doi', include_relation=False)

0 commit comments

Comments
 (0)