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
20 changes: 14 additions & 6 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2696,24 +2696,32 @@ def _validate_operations_result(
if result.get("success"):
return None

print(result)
for op_result in result["operations"]:
self.log.warning(
"Operations failed. Server response:\n%s",
json.dumps(result, indent=4, default=str),
)
for op_result in result.get("operations") or []:
if op_result["success"]:
continue

operation_id = op_result["id"]
operation = next(
op
for op in operations_body
if op["id"] == operation_id
(op for op in operations_body if op["id"] == operation_id),
op_result,
)
detail = op_result["detail"]
raise FailedOperations(
f"Operation \"{operation_id}\" failed with data:"
f"\n{json.dumps(operation, indent=4)}"
f"\n{json.dumps(operation, indent=4, default=str)}"
f"\nDetail: {detail}."
)

# Server did not report which operation failed
raise FailedOperations(
"Operations failed. Server response:"
f"\n{json.dumps(result, indent=4, default=str)}"
)

def _prepare_fields(
self,
entity_type: str,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_operations_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Validation of operations result. Does not require running AYON server."""
import pytest

from ayon_api.exceptions import FailedOperations
from ayon_api.server_api import ServerAPI


@pytest.fixture
def con():
return ServerAPI("http://localhost:0", create_session=False)
Comment thread
BigRoy marked this conversation as resolved.


def test_failed_result_without_failed_operation_raises(con, capsys):
result = {"success": False, "operations": [{"id": "a", "success": True}]}
with pytest.raises(FailedOperations, match="Server response"):
con._validate_operations_result(result, [{"id": "a"}])
assert capsys.readouterr().out == ""


def test_failed_operation_raises_with_detail(con):
result = {
"success": False,
"operations": [{"id": "a", "success": False, "detail": "Boom"}],
}
with pytest.raises(FailedOperations, match="Boom"):
con._validate_operations_result(result, [{"id": "a", "type": "x"}])
Loading