Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion plugins/nemo-auditor/src/nemo_auditor/api/v2/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@
detail=f"AuditConfig '{name}' not found in workspace '{workspace}'.",
) from exc
except NemoEntityConflictError as exc:
raise HTTPException(status_code=409, detail=str(exc)) from exc
logger.info("Conflict updating audit config '%s' in workspace '%s'", name, workspace, exc_info=True)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
raise HTTPException(
status_code=409,
detail=(
f"AuditConfig '{name}' was modified by another request in workspace '{workspace}'. "
"Refresh the config and try again."
),
) from exc
except Exception as exc:
logger.exception("Failed to update audit config '%s'", name)
raise HTTPException(status_code=500, detail="Failed to update audit config.") from exc
Expand Down
9 changes: 8 additions & 1 deletion plugins/nemo-auditor/src/nemo_auditor/api/v2/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@
detail=f"AuditTarget '{name}' not found in workspace '{workspace}'.",
) from exc
except NemoEntityConflictError as exc:
raise HTTPException(status_code=409, detail=str(exc)) from exc
logger.info("Conflict updating audit target '%s' in workspace '%s'", name, workspace, exc_info=True)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
raise HTTPException(
status_code=409,
detail=(
f"AuditTarget '{name}' was modified by another request in workspace '{workspace}'. "
"Refresh the target and try again."
),
) from exc
except Exception as exc:
logger.exception("Failed to update audit target '%s'", name)
raise HTTPException(status_code=500, detail="Failed to update audit target.") from exc
Expand Down
18 changes: 18 additions & 0 deletions plugins/nemo-auditor/tests/test_api_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ def test_invalid_payload_returns_422(self, client, mock_entity_client) -> None:
)
assert resp.status_code == 422

def test_conflict_hides_raw_exception_details(self, client, mock_entity_client) -> None:
mock_entity_client.get = AsyncMock(return_value=_make_config("cfg-1"))
mock_entity_client.update = AsyncMock(
side_effect=NemoEntityConflictError("Error code: 409 - {'detail': 'db_version mismatch'}")
)

resp = client.put(
"/apis/auditor/v2/workspaces/default/configs/cfg-1",
json={"description": "new"},
)

assert resp.status_code == 409
detail = resp.json()["detail"]
assert "AuditConfig 'cfg-1'" in detail
assert "Refresh the config" in detail
assert "Error code" not in detail
assert "db_version" not in detail


class TestDeleteConfig:
def test_returns_204(self, client, mock_entity_client) -> None:
Expand Down
18 changes: 18 additions & 0 deletions plugins/nemo-auditor/tests/test_api_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ def test_404_when_missing(self, client, mock_entity_client) -> None:
)
assert resp.status_code == 404

def test_conflict_hides_raw_exception_details(self, client, mock_entity_client) -> None:
mock_entity_client.get = AsyncMock(return_value=_make_target("tgt-1"))
mock_entity_client.update = AsyncMock(
side_effect=NemoEntityConflictError("Error code: 409 - {'detail': 'db_version mismatch'}")
)

resp = client.put(
"/apis/auditor/v2/workspaces/default/targets/tgt-1",
json={"type": "nim", "model": "x"},
)

assert resp.status_code == 409
detail = resp.json()["detail"]
assert "AuditTarget 'tgt-1'" in detail
assert "Refresh the target" in detail
assert "Error code" not in detail
assert "db_version" not in detail


class TestDeleteTarget:
def test_returns_204(self, client, mock_entity_client) -> None:
Expand Down
Loading
Loading