Skip to content

Commit

Permalink
gcp/api: return next page token if query by generic version (#1804)
Browse files Browse the repository at this point in the history
Addressing comment here
#1783 (comment)
  • Loading branch information
cuixq authored Nov 15, 2023
1 parent 3c60556 commit 7331518
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions gcp/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,20 @@ def query_by_version(context: QueryContext,
if ecosystem:
if is_semver:
# Ecosystem supports semver only.
bugs, next_page_token = yield _query_by_semver(context, query,
package_name, ecosystem,
purl, version)
bugs, _ = yield _query_by_semver(context, query, package_name, ecosystem,
purl, version)

new_bugs, _ = yield _query_by_generic_version(context, query,
package_name, ecosystem,
purl, version)
for bug in new_bugs:
if bug not in bugs:
bugs.append(bug)

else:
bugs, next_page_token = yield _query_by_generic_version(
context, query, package_name, ecosystem, purl, version)

else:
logging.warning("Package query without ecosystem specified")
# Unspecified ecosystem. Try semver first.
Expand All @@ -877,17 +888,16 @@ def query_by_version(context: QueryContext,
ecosystem, purl, version)
bugs.extend(new_bugs)

# Try querying by generic version for all cases.
new_bugs, _ = yield _query_by_generic_version(context, query, package_name,
ecosystem, purl, version)
for bug in new_bugs:
if bug not in bugs:
bugs.append(bug)
new_bugs, _ = yield _query_by_generic_version(context, query, package_name,
ecosystem, purl, version)
for bug in new_bugs:
if bug not in bugs:
bugs.append(bug)

# Trying both is too difficult/ugly with paging
# Our documentation states that this is an invalid query
# context.service_context.abort(grpc.StatusCode.INVALID_ARGUMENT,
# 'Ecosystem not specified')
# Trying both is too difficult/ugly with paging
# Our documentation states that this is an invalid query
# context.service_context.abort(grpc.StatusCode.INVALID_ARGUMENT,
# 'Ecosystem not specified')

return [to_response(bug) for bug in bugs], next_page_token

Expand Down

0 comments on commit 7331518

Please sign in to comment.