Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit a33307c

Browse files
fix: Fix query for is_first_pull_request
1 parent c3ff910 commit a33307c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

graphql_api/tests/test_repository.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ def test_repository_is_first_pull_request(self) -> None:
513513

514514
assert data["me"]["owner"]["repository"]["isFirstPullRequest"] == True
515515

516+
assert (
517+
repo.pull_requests.values("id")[:2].query
518+
== 'SELECT "pull_requests"."id" FROM "pull_requests" WHERE "pull_requests"."repoid" = 1 ORDER BY "pull_requests"."pullid" DESC LIMIT 2'
519+
)
520+
516521
def test_repository_is_first_pull_request_compared_to_not_none(self) -> None:
517522
repo = RepositoryFactory(
518523
author=self.owner,

graphql_api/types/repository/repository.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
from graphql_api.actions.commits import repo_commits
1515
from graphql_api.dataloader.commit import CommitLoader
1616
from graphql_api.dataloader.owner import OwnerLoader
17-
from graphql_api.helpers.connection import (
18-
queryset_to_connection,
19-
)
17+
from graphql_api.helpers.connection import queryset_to_connection
2018
from graphql_api.types.coverage_analytics.coverage_analytics import (
2119
CoverageAnalyticsProps,
2220
)
@@ -267,13 +265,16 @@ def resolve_repository_result_type(obj: Any, *_: Any) -> Optional[str]:
267265
def resolve_is_first_pull_request(
268266
repository: Repository, info: GraphQLResolveInfo
269267
) -> bool:
270-
has_one_pr = repository.pull_requests.count() == 1
271-
272-
if has_one_pr:
273-
first_pr = repository.pull_requests.first()
274-
return not first_pr.compared_to
275-
276-
return False
268+
try:
269+
# SELECT "pull_requests"."id" FROM "pull_requests" WHERE "pull_requests"."repoid" = 1 ORDER BY "pull_requests"."pullid" DESC LIMIT 2
270+
pull_requests = repository.pull_requests.values("id")[:2]
271+
return len(pull_requests) == 1
272+
except Exception as e:
273+
log.error(
274+
"Error checking is_first_pull_request",
275+
extra=dict(repo_id=repository.repoid, error=str(e)),
276+
)
277+
return False
277278

278279

279280
@repository_bindable.field("isGithubRateLimited")

0 commit comments

Comments
 (0)