Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 50b7b6d

Browse files
[client] handle draft read only errors (opencti #9300)
1 parent 391d326 commit 50b7b6d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def _process_message(self, channel, method, properties, body) -> None:
247247
{"tag": method.delivery_tag},
248248
)
249249

250+
def _set_draft_id(self, draft_id):
251+
self.helper.draft_id = draft_id
252+
self.helper.api.set_draft_id(draft_id)
253+
self.helper.api_impersonate.set_draft_id(draft_id)
254+
250255
def _data_handler(self, json_data) -> None:
251256
# Execute the callback
252257
try:
@@ -261,9 +266,7 @@ def _data_handler(self, json_data) -> None:
261266
self.helper.work_id = work_id
262267

263268
self.helper.validation_mode = validation_mode
264-
self.helper.draft_id = draft_id
265-
self.helper.api.set_draft_id(draft_id)
266-
self.helper.api_impersonate.set_draft_id(draft_id)
269+
self._set_draft_id(draft_id)
267270

268271
self.helper.playbook = None
269272
self.helper.enrichment_shared_organizations = None
@@ -360,12 +363,14 @@ def _data_handler(self, json_data) -> None:
360363
message = self.callback(event_data)
361364
if work_id:
362365
self.helper.api.work.to_processed(work_id, message)
366+
self._set_draft_id("")
363367

364368
except Exception as e: # pylint: disable=broad-except
365369
self.helper.metric.inc("error_count")
366370
self.helper.connector_logger.error(
367371
"Error in message processing, reporting error to API"
368372
)
373+
self._set_draft_id("")
369374
if work_id:
370375
try:
371376
self.helper.api.work.to_processed(work_id, str(e), True)

pycti/utils/opencti_stix2.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
ERROR_TYPE_LOCK = "LOCK_ERROR"
4141
ERROR_TYPE_MISSING_REFERENCE = "MISSING_REFERENCE_ERROR"
4242
ERROR_TYPE_BAD_GATEWAY = "Bad Gateway"
43+
ERROR_TYPE_DRAFT_LOCK = "DRAFT_LOCKED"
4344
ERROR_TYPE_TIMEOUT = "Request timed out"
4445

4546
# Extensions
@@ -2408,7 +2409,11 @@ def export_selected(
24082409
return bundle
24092410

24102411
def apply_patch_files(self, item):
2411-
field_patch = item["opencti_field_patch"]
2412+
field_patch = self.opencti.get_attribute_in_extension(
2413+
"opencti_field_patch", item
2414+
)
2415+
if field_patch is None:
2416+
field_patch = item["opencti_field_patch"]
24122417
field_patch_files = next(
24132418
(op for op in field_patch if op["key"] == "x_opencti_files"), None
24142419
)
@@ -2671,6 +2676,19 @@ def import_item(
26712676
return self.import_item(
26722677
item, update, types, processing_count + 1, work_id
26732678
)
2679+
# A draft lock error occurs
2680+
elif ERROR_TYPE_DRAFT_LOCK in error_msg:
2681+
bundles_technical_error_counter.add(1)
2682+
if work_id is not None:
2683+
self.opencti.work.api.set_draft_id("")
2684+
self.opencti.work.report_expectation(
2685+
work_id,
2686+
{
2687+
"error": error,
2688+
"source": "Draft in read only",
2689+
},
2690+
)
2691+
return False
26742692
# Platform does not know what to do and raises an error:
26752693
# That also works for missing reference with too much execution
26762694
else:

0 commit comments

Comments
 (0)