@@ -1315,6 +1315,10 @@ public List<T> search(final SearchCriteria<T> sc, final Filter filter) {
13151315 public Pair <List <T >, Integer > searchAndCount (final SearchCriteria <T > sc , final Filter filter ) {
13161316 List <T > objects = search (sc , filter , null , false );
13171317 Integer count = getCount (sc );
1318+ // Count cannot be less than the result set but can be higher due to pagination, see CLOUDSTACK-10320
1319+ if (count < objects .size ()) {
1320+ count = objects .size ();
1321+ }
13181322 return new Pair <List <T >, Integer >(objects , count );
13191323 }
13201324
@@ -1323,6 +1327,11 @@ public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final F
13231327 public Pair <List <T >, Integer > searchAndDistinctCount (final SearchCriteria <T > sc , final Filter filter ) {
13241328 List <T > objects = search (sc , filter , null , false );
13251329 Integer count = getDistinctCount (sc );
1330+ // Count cannot be 0 if there is at least a result in the list, see CLOUDSTACK-10320
1331+ if (count == 0 && !objects .isEmpty ()) {
1332+ // Cannot assume if it's more than one since the count is distinct vs search
1333+ count = 1 ;
1334+ }
13261335 return new Pair <List <T >, Integer >(objects , count );
13271336 }
13281337
@@ -1331,6 +1340,11 @@ public Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T> sc,
13311340 public Pair <List <T >, Integer > searchAndDistinctCount (final SearchCriteria <T > sc , final Filter filter , final String [] distinctColumns ) {
13321341 List <T > objects = search (sc , filter , null , false );
13331342 Integer count = getDistinctCount (sc , distinctColumns );
1343+ // Count cannot be 0 if there is at least a result in the list, see CLOUDSTACK-10320
1344+ if (count == 0 && !objects .isEmpty ()) {
1345+ // Cannot assume if it's more than one since the count is distinct vs search
1346+ count = 1 ;
1347+ }
13341348 return new Pair <List <T >, Integer >(objects , count );
13351349 }
13361350
0 commit comments