Brief
Separate accepted and doubtful messages while preserving originals, then process a traceable correction.
Voss asks for malformed TRANSFER-7 to be deleted before the meeting. Mara refuses: that page may explain why your name appears elsewhere. Imani needs a delivery record showing what was received, rejected, and corrected. You have complete a1, a2 without operator, cut-off JSON a3, and a4 offered as a correction to a2. The urgency is fictional; the exercise has no timer.
Your mission
- Classify a1, a2, and a3 and give each rejection's error code.
- List four items to retain for a quarantined entry.
- Explain what changes and what remains after a4 arrives.
- Say why accepting a4's shape does not prove OP-17 actually initiated the transfer.
How to check your work
- a1 accepted; a2 MISSING_OPERATOR; a3 BAD_JSON.
- delivery_id, source_file, raw_payload, and error_code remain available.
- a4 is a new delivery linked to a2; a2 is not erased.
- The supplier claims OP-17, but source and actor require corroboration.
Course example
import json
delivered = [
("a1", "supplier-page3.json", '{"event_id":"E8","operator_id":"OP-8"}'),
("a2", "supplier-page2.json", '{"event_id":"TRANSFER-7"}'),
("a3", "supplier-page4.json", '{"event_id":'),
]
accepted = []
quarantine = []
def route(delivery_id, source_file, raw_payload):
try:
event = json.loads(raw_payload)
except json.JSONDecodeError:
quarantine.append((delivery_id, source_file, raw_payload, "BAD_JSON"))
return
if not isinstance(event, dict):
quarantine.append((delivery_id, source_file, raw_payload, "BAD_SHAPE"))
elif "operator_id" not in event:
quarantine.append((delivery_id, source_file, raw_payload, "MISSING_OPERATOR"))
elif not isinstance(event["operator_id"], str) or not event["operator_id"].strip():
quarantine.append((delivery_id, source_file, raw_payload, "BAD_OPERATOR"))
else:
accepted.append((delivery_id, event))
for delivery in delivered:
route(*delivery)
print(len(accepted), len(quarantine))
print([(item[0], item[3]) for item in quarantine])
correction = (
"a4", "supplier-correction.json",
'{"event_id":"TRANSFER-7","operator_id":"OP-17","correction_of":"a2"}'
)
original = quarantine[0] # a2 in this small exercise
new_event = json.loads(correction[2])
if (new_event.get("correction_of") == original[0]
and new_event.get("event_id") == json.loads(original[2]).get("event_id")):
route(*correction)
resolution = {"rejected_delivery_id": original[0], "new_delivery_id": correction[0]}
else:
quarantine.append((*correction, "BAD_CORRECTION_LINK"))
resolution = None
print(len(accepted), len(quarantine))
print(resolution)