Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fe544a

Browse filesBrowse files
feat: generate RFC json at publication time (#11143)
* feat: generate RFC json at publication time Deprecates uploading json files and ignores the file, instead generating its own. * refactor: partial() instead of lambda in on_commit Using partial() is safer as general practice because it binds arguments at call-time. * test: json upload ignored, creation task queued
1 parent e736082 commit 1fe544a
Copy full SHA for 1fe544a

3 files changed

+33-12Lines changed: 33 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎ietf/api/serializers_rpc.py‎

Copy file name to clipboardExpand all lines: ietf/api/serializers_rpc.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ class RfcFileSerializer(serializers.Serializer):
805805
# works.
806806
allowed_extensions = (
807807
".html",
808-
".json",
808+
".json", # deprecated - accepted but ignored, datatracker generates its own
809809
".notprepped.xml",
810810
".pdf",
811811
".txt",
Collapse file

‎ietf/api/tests_views_rpc.py‎

Copy file name to clipboardExpand all lines: ietf/api/tests_views_rpc.py
+21-8Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def test_notify_rfc_published(self, mock_task_delay):
224224
self.assertEqual(mock_kwargs["rfc_number_list"], expected_rfc_number_list)
225225

226226
@override_settings(APP_API_TOKENS={"ietf.api.views_rpc": ["valid-token"]})
227+
@mock.patch("ietf.api.views_rpc.update_rfc_json_task")
227228
@mock.patch("ietf.api.views_rpc.rebuild_reference_relations_task")
228229
@mock.patch("ietf.api.views_rpc.update_rfc_searchindex_task")
229230
@mock.patch("ietf.api.views_rpc.trigger_red_precomputer_task")
@@ -232,6 +233,7 @@ def test_upload_rfc_files(
232233
mock_trigger_red_task,
233234
mock_update_searchindex_task,
234235
mock_rebuild_relations,
236+
mock_update_rfc_json,
235237
):
236238
def _valid_post_data():
237239
"""Generate a valid post data dict
@@ -292,7 +294,7 @@ def _valid_post_data():
292294
ContentFile(b"", "myfile.txt"),
293295
ContentFile(b"", "myfile.html"),
294296
ContentFile(b"", "myfile.pdf"),
295-
ContentFile(b"", "myfile.json"),
297+
ContentFile(b"", "myfile.json"), # deprecated!
296298
ContentFile(b"", "myfile.notprepped.xml"),
297299
]
298300
},
@@ -346,18 +348,19 @@ def _valid_post_data():
346348

347349
# valid post
348350
mock_trigger_red_task.delay.reset_mock()
349-
r = self.client.post(
350-
url,
351-
_valid_post_data(),
352-
format="multipart",
353-
headers={"X-Api-Key": "valid-token"},
354-
)
351+
with self.captureOnCommitCallbacks(execute=True):
352+
r = self.client.post(
353+
url,
354+
_valid_post_data(),
355+
format="multipart",
356+
headers={"X-Api-Key": "valid-token"},
357+
)
355358
self.assertEqual(r.status_code, 200)
356359
self.assertEqual(
357360
mock_update_searchindex_task.delay.call_args,
358361
mock.call(rfc.rfc_number),
359362
)
360-
for extension in ["xml", "txt", "html", "pdf", "json"]:
363+
for extension in ["xml", "txt", "html", "pdf"]: # no "json"!
361364
filename = f"{rfc.name}.{extension}"
362365
self.assertEqual(
363366
(rfc_path / filename).read_text(),
@@ -389,6 +392,12 @@ def _valid_post_data():
389392
b"This is .notprepped.xml",
390393
".notprepped.xml blob should contain the expected content",
391394
)
395+
# special case for json (deprecated and should be ignored)
396+
self.assertFalse((rfc_path / f"{rfc.name}.json").exists())
397+
self.assertFalse(
398+
Blob.objects.filter(bucket="rfc", name=f"json/{rfc.name}.json").exists()
399+
)
400+
392401
# Confirm that the red precomputer was triggered correctly
393402
self.assertTrue(mock_trigger_red_task.delay.called)
394403
_, mock_kwargs = mock_trigger_red_task.delay.call_args
@@ -404,6 +413,10 @@ def _valid_post_data():
404413
_, mock_kwargs = mock_rebuild_relations.delay.call_args
405414
self.assertIn("doc_names", mock_kwargs)
406415
self.assertEqual(mock_kwargs["doc_names"], [rfc.name])
416+
# Confirm rfc JSON creation was triggered correctly
417+
self.assertTrue(mock_update_rfc_json.delay.called)
418+
mock_args, _ = mock_update_rfc_json.delay.call_args
419+
self.assertEqual(mock_args[0], [rfc.rfc_number])
407420

408421
# re-post with replace = False should now fail
409422
mock_update_searchindex_task.reset_mock()
Collapse file

‎ietf/api/views_rpc.py‎

Copy file name to clipboardExpand all lines: ietf/api/views_rpc.py
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright The IETF Trust 2023-2026, All Rights Reserved
22
import os
33
import shutil
4+
from functools import partial
45
from pathlib import Path
56
from tempfile import TemporaryDirectory
67

@@ -463,7 +464,9 @@ def post(self, request):
463464
{d.rfc_number for d in rfc.related_that_doc(("updates", "obs"))}
464465
)
465466
if related_numbers:
466-
transaction.on_commit(lambda: update_rfc_json_task.delay(related_numbers))
467+
# Only update json for related rfcs. We can't generate json for _this_ rfc
468+
# until we receive the files and know what formats we have.
469+
transaction.on_commit(partial(update_rfc_json_task.delay, related_numbers))
467470
return Response(NotificationAckSerializer().data)
468471

469472

@@ -523,6 +526,10 @@ def post(self, request):
523526
for upfile in uploaded_files:
524527
uploaded_filename = Path(upfile.name) # name supplied by request
525528
uploaded_ext = "".join(uploaded_filename.suffixes)
529+
# Ignore json files, which are deprecated. Remove this when purple no
530+
# longer tries to send them.
531+
if uploaded_ext == ".json":
532+
continue
526533
tempfile_path = tmpfile_stem.with_suffix(uploaded_ext)
527534
with tempfile_path.open("wb") as dest:
528535
for chunk in upfile.chunks():
@@ -565,9 +572,10 @@ def post(self, request):
565572
trigger_red_precomputer_task.delay(rfc_number_list=sorted(needs_updating))
566573
# Trigger search index update
567574
update_rfc_searchindex_task.delay(rfc.rfc_number)
568-
# Trigger reference relation srebuild
575+
# Trigger reference relations rebuild
569576
rebuild_reference_relations_task.delay(doc_names=[rfc.name])
570-
577+
# Build rfc json (json for related rfcs was updated in RfcPubNotificationView)
578+
transaction.on_commit(partial(update_rfc_json_task.delay, [rfc.rfc_number]))
571579
return Response(NotificationAckSerializer().data)
572580

573581

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.