Skip to content

bug: findByOne and findTop not passing limit to Query Engine #630

@bsbodden

Description

@bsbodden

Redis OM Spring is not properly implementing the limiting functionality from Spring Data's PartTree. The findTop2ByOrderByYearFoundedAsc method is returning
all 3 results instead of limiting to 2.

Summary

After investigating the codebase and running tests, I can confirm that findTop1ByTeamOrderByDueDateAsc is NOT actually supported in Redis OM Spring as expected. Here's what I found:

  1. Missing Implementation: Redis OM Spring's RediSearchQuery class creates a PartTree from the method name but never checks pt.isLimiting() or pt.getMaxResults() to extract the limit value from
    method names like findTop, findFirst, or findTop[N].
  2. Current Behavior: Methods like findTopByTeamOrderByDueDateAsc or findTop1ByTeamOrderByDueDateAsc will execute but will use the default limit from
    redisOMProperties.getRepository().getQuery().getLimit(), which defaults to 10,000.
  3. Test Evidence: The test I created shows that findTop2ByOrderByYearFoundedAsc returns all 3 records instead of limiting to 2, confirming the functionality is not implemented.
  4. Workarounds Available:
    - Use @query annotation with @limit
    - Use Pageable with PageRequest.of(0, 1)
    - Use Entity Streams with .limit(1)

The issue is in the processPartTree method in RediSearchQuery.java which needs to be enhanced to check for limiting:

// This needs to be added after line 382 in processPartTree method:
if (pt.isLimiting()) {
this.limit = pt.getMaxResults().orElse(1);
}

This is a missing feature in Redis OM Spring that should be implemented to fully support Spring Data's query derivation capabilities.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions