Skip to content

Commit 10a4d68

Browse files
refactor(datasets): count the same id field the insert binds
Drop the fall back to item.id() when datasetItemId is null. It looked defensive but was worse than nothing: the INSERT ten lines below binds item.datasetItemId().toString() with no null check, so a null cannot survive to be counted either way, and every caller normalizes datasetItemId before reaching here. All the fallback added was a second, divergent definition of item identity in the one place that must agree with what the INSERT writes. Addresses review feedback on #7966. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c37e5c6 commit 10a4d68

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

apps/opik-backend/src/main/java/com/comet/opik/domain/DatasetItemVersionDAO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,10 +3502,11 @@ public Mono<Long> insertItems(@NonNull UUID datasetId, @NonNull UUID newVersionI
35023502
//
35033503
// Count DISTINCT stable ids, not rows handed in (OPIK-7891): reads collapse a repeated
35043504
// dataset_item_id to one row via LIMIT 1 BY, so counting the raw list inflates every
3505-
// version total derived from this value. Callers set datasetItemId before inserting;
3506-
// fall back to id so an unnormalized item still counts as itself rather than as null.
3505+
// version total derived from this value. Counting the same field the INSERT binds below
3506+
// keeps one definition of identity -- every caller normalizes datasetItemId first, and a
3507+
// null would fail at the bind regardless, so there is nothing to fall back to.
35073508
long itemCount = items.stream()
3508-
.map(item -> item.datasetItemId() != null ? item.datasetItemId() : item.id())
3509+
.map(DatasetItem::datasetItemId)
35093510
.distinct()
35103511
.count();
35113512

0 commit comments

Comments
 (0)