DaanHoogland closed pull request #2481: CLOUDSTACK-10320 - Invalid pair for
response object breaking response parsing
URL: https://github.com/apache/cloudstack/pull/2481
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
index 304a122a0b7..442d3cc181d 100644
--- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
+++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
@@ -1315,6 +1315,10 @@ protected void addJoins(StringBuilder str,
Collection<JoinBuilder<SearchCriteria
public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc,
final Filter filter) {
List<T> objects = search(sc, filter, null, false);
Integer count = getCount(sc);
+ // Count cannot be less than the result set but can be higher due to
pagination, see CLOUDSTACK-10320
+ if (count < objects.size()) {
+ count = objects.size();
+ }
return new Pair<List<T>, Integer>(objects, count);
}
@@ -1323,6 +1327,11 @@ protected void addJoins(StringBuilder str,
Collection<JoinBuilder<SearchCriteria
public Pair<List<T>, Integer> searchAndDistinctCount(final
SearchCriteria<T> sc, final Filter filter) {
List<T> objects = search(sc, filter, null, false);
Integer count = getDistinctCount(sc);
+ // Count cannot be 0 if there is at least a result in the list, see
CLOUDSTACK-10320
+ if (count == 0 && !objects.isEmpty()) {
+ // Cannot assume if it's more than one since the count is distinct
vs search
+ count = 1;
+ }
return new Pair<List<T>, Integer>(objects, count);
}
@@ -1331,6 +1340,11 @@ protected void addJoins(StringBuilder str,
Collection<JoinBuilder<SearchCriteria
public Pair<List<T>, Integer> searchAndDistinctCount(final
SearchCriteria<T> sc, final Filter filter, final String[] distinctColumns) {
List<T> objects = search(sc, filter, null, false);
Integer count = getDistinctCount(sc, distinctColumns);
+ // Count cannot be 0 if there is at least a result in the list, see
CLOUDSTACK-10320
+ if (count == 0 && !objects.isEmpty()) {
+ // Cannot assume if it's more than one since the count is distinct
vs search
+ count = 1;
+ }
return new Pair<List<T>, Integer>(objects, count);
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services