Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cognite/extractorutils/unstable/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ def _handle_custom_action(self, action: Action) -> None:
external_id=action.external_id,
status=completed_status,
result_message=truncate_message(
f"Action '{custom.name}' {outcome}, but metadata field(s) "
f"{', '.join(oversized_fields)} exceeded the {MAX_METADATA_VALUE_BYTES}-byte-per-value "
f"limit and were dropped from the reported result"
f"Action '{custom.name}' {outcome}, but {len(oversized_fields)} metadata field(s) "
f"exceeded the {MAX_METADATA_VALUE_BYTES}-byte-per-value limit and were dropped from "
f"the reported result: {', '.join(oversized_fields)}"
),
result_metadata=filtered_metadata,
)
Expand All @@ -813,8 +813,10 @@ def _handle_custom_action(self, action: Action) -> None:
str(e)
if not oversized_fields
else truncate_message(
f"{e} (additionally, metadata field(s) {', '.join(oversized_fields)} exceeded "
f"the {MAX_METADATA_VALUE_BYTES}-byte-per-value limit and were dropped)"
f"{len(oversized_fields)} metadata field(s) exceeded the "
f"{MAX_METADATA_VALUE_BYTES}-byte-per-value limit and were dropped. "
f"Action failed: {truncate_message(str(e), max_length=500)}. "
f"Dropped fields: {', '.join(oversized_fields)}"
)
),
result_metadata=filtered_metadata,
Expand Down
12 changes: 11 additions & 1 deletion tests/test_unstable/test_action_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def target(ctx: ActionContext) -> None:
assert final.result_message is not None
assert len(final.result_message) <= MAX_MESSAGE_LENGTH
assert final.result_message.endswith("...")
# Regression: the explanation, including the count, must survive truncation even when the
# field-name list doesn't.
assert "45 metadata field(s) exceeded" in final.result_message
assert "dropped" in final.result_message


def test_oversized_action_error_with_long_message_truncates_instead_of_crashing() -> None:
Expand All @@ -427,7 +431,13 @@ def target(ctx: ActionContext) -> None:
assert failed.result_metadata == {"error_type": "invalid_parameter"}
assert failed.result_message is not None
assert len(failed.result_message) <= MAX_MESSAGE_LENGTH
assert failed.result_message.endswith("...")
# Regression: the metadata-dropped explanation must survive truncation even when the
# ActionError message itself is long enough to need truncating on its own.
assert "exceeded" in failed.result_message
assert "dropped" in failed.result_message
# Regression: str(e) is bounded before combining, so there's still room left for the
# dropped-field-name list even when the ActionError message alone is very long.
assert "error_detail" in failed.result_message


def test_custom_action_receives_call_metadata_in_context() -> None:
Expand Down
Loading