Skip to content

fix(backend): raise ItemDeletedException for soft-deleted rows across CRUD, services, and tasks - #2508

Merged
EmanueleDeRossi1 merged 15 commits into
mainfrom
lazy-load-test-fixture-fixes
Aug 19, 2026
Merged

fix(backend): raise ItemDeletedException for soft-deleted rows across CRUD, services, and tasks#2508
EmanueleDeRossi1 merged 15 commits into
mainfrom
lazy-load-test-fixture-fixes

Conversation

@EmanueleDeRossi1

@EmanueleDeRossi1 EmanueleDeRossi1 commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Several single-item "get by ID" functions returned None for both "doesn't exist" and "soft-deleted", unlike the standard get_item_detail contract that raises ItemDeletedException (-> HTTP 410 instead of 404). Surfaced from a code comment in crud/metric.py explaining why get_metric skipped the standard pattern — turned out to be one of several.

What Changed

  • crud/ layer: get_metric, get_test_set, get_test_set_by_nano_id_or_slug, get_trace_by_db_id now raise correctly; get_model deliberately kept its None-for-deleted contract (it's used elsewhere as an internal fallback resolver) but its organization filter now raises instead of silently skipping when empty; simplified several already-correct getters to call get_item_detail directly instead of duplicating its logic
  • services/ and tasks/ layer: the same fix applied to EndpointService._get_endpoint, the batch execution context's endpoint and test fetches, get_test_and_prompt, all four GarakSyncService lookups, the test-set association helpers in services/test.py, get_prompts_for_test_set, all four preflight check functions, the test-generation attach-tests task, and services.test_set.get_test_set
  • Fixed two exception-swallowing spots (the handle_database_exceptions decorator, handle_execution_error) that would otherwise turn the new exception into a bare 500
  • Fixed a regression this same work introduced in already-shipped code: update_test_set_attributes depended on the old None-returning behavior to no-op gracefully, and would have started throwing on ordinary test updates
  • Removed confirmed-dead functions found along the way: get_span_by_id, get_tool_by_provider

Testing

Added regression tests for every fixed getter; several were verified by temporarily reverting the fix and confirming the test fails first. Full backend suite passes.

@peqy

peqy Bot commented Aug 17, 2026

Copy link
Copy Markdown

[Improvement] Possible missing import after telemetry refactor

In apps/backend/src/rhesis/backend/app/crud/telemetry.py:get_trace_by_db_id, the function now calls UUID(trace_db_id) but the local from uuid import UUID import was removed in the diff. If UUID isn’t imported at module scope, this will raise NameError.

Fix: ensure UUID is in scope (either re-add the local import or import it at the top of the module).

Overall, the soft-delete contract unification + tests look solid.

Found 1 issue (0 critical, 1 improvement).

@EmanueleDeRossi1
EmanueleDeRossi1 force-pushed the lazy-load-test-fixture-fixes branch from 71869cb to 6a8b4b6 Compare August 18, 2026 09:16
@EmanueleDeRossi1
EmanueleDeRossi1 changed the base branch from main to fix/querybuilder-cleanup-and-filters August 18, 2026 09:16
@EmanueleDeRossi1 EmanueleDeRossi1 changed the title Fix soft-delete consistency across CRUD, services, and tasks fix(backend): raise ItemDeletedException for soft-deleted rows across CRUD, services, and tasks Aug 18, 2026

@peqy peqy Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on my prior note: crud/telemetry.py now has from uuid import UUID at module scope, so UUID(trace_db_id) in get_trace_by_db_id is in scope.

Overall the soft-delete contract unification + org scoping + count fix look solid. Ship it.

Base automatically changed from fix/querybuilder-cleanup-and-filters to main August 18, 2026 09:54
@EmanueleDeRossi1
EmanueleDeRossi1 force-pushed the lazy-load-test-fixture-fixes branch 2 times, most recently from f422a48 to 4334c9e Compare August 18, 2026 11:57

@peqy peqy Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the earlier concern is addressed: crud/telemetry.py has from uuid import UUID at module scope, so get_trace_by_db_id() won’t hit a NameError.

The soft-delete contract unification (raising ItemDeletedException/410) and the “don’t swallow ItemDeletedException” fixes in handle_database_exceptions + handle_execution_error look consistent. Ship it.

@peqy

peqy Bot commented Aug 18, 2026

Copy link
Copy Markdown

Re-checked crud/telemetry.py: UUID is imported at module scope now, so the earlier NameError concern in get_trace_by_db_id looks resolved.

No further issues spotted in the updated diff. Ship it.

…ed rows

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…eted rows

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…ft-deleted rows

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…il directly

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…st sets

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…ation

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…or test-set lookups

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
…cstrings

Signed-off-by: Emanuele De Rossi <emanuele.derossi@rhesis.ai>
@EmanueleDeRossi1
EmanueleDeRossi1 force-pushed the lazy-load-test-fixture-fixes branch from 348a9c0 to de79399 Compare August 19, 2026 09:42
@EmanueleDeRossi1
EmanueleDeRossi1 merged commit 2b61a7f into main Aug 19, 2026
15 of 16 checks passed
@EmanueleDeRossi1
EmanueleDeRossi1 deleted the lazy-load-test-fixture-fixes branch August 19, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant