Skip to content

fix(bots): ensure deterministic ordering of GitHub app installations#918

Merged
drazisil-codecov merged 2 commits into
mainfrom
joebecher/fix-github-app-selection-order
May 8, 2026
Merged

fix(bots): ensure deterministic ordering of GitHub app installations#918
drazisil-codecov merged 2 commits into
mainfrom
joebecher/fix-github-app-selection-order

Conversation

@drazisil-codecov
Copy link
Copy Markdown
Contributor

@drazisil-codecov drazisil-codecov commented May 7, 2026

Summary

  • DjangoSQLAlchemyOwnerWrapper.get_github_app_installations had no ORDER BY, so the DB could return installations in any order — making app[0] non-deterministic across calls
  • Added order_by("id") to the Django path in owner_helper.py
  • Added order_by="GithubAppInstallation.id" to the SQLAlchemy relationship in core.py

Test plan

  • New test in TestGithubAppInstallationsOrdering creates 3 apps, deletes and recreates one (forcing its ID higher than the others), and asserts the wrapper always returns them sorted by id
  • All existing test_github_apps.py tests pass

🤖 Generated with Claude Code


Note

Low Risk
Low risk: adds explicit ordering to ORM queries/relationships so callers no longer depend on database return order; main impact is making GitHub app selection deterministic when lists are iterated/indexed.

Overview
Ensures deterministic ordering of Owner.github_app_installations across both ORM implementations.

Adds ORDER BY id for Django (DjangoSQLAlchemyOwnerWrapper.get_github_app_installations) and sets order_by="GithubAppInstallation.id_" on the SQLAlchemy Owner.github_app_installations relationship, plus a unit test that verifies the wrapper returns installations sorted by id even after delete/recreate changes row IDs.

Reviewed by Cursor Bugbot for commit 69eea4b. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7fcc00d. Configure here.

Comment thread apps/worker/database/models/core.py Outdated
@sentry
Copy link
Copy Markdown
Contributor

sentry Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.89%. Comparing base (2e45f4f) to head (69eea4b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #918   +/-   ##
=======================================
  Coverage   91.89%   91.89%           
=======================================
  Files        1316     1316           
  Lines       50640    50640           
  Branches     1625     1625           
=======================================
  Hits        46538    46538           
  Misses       3796     3796           
  Partials      306      306           
Flag Coverage Δ
apiunit 94.95% <ø> (ø)
sharedintegration 36.96% <0.00%> (ø)
sharedunit 84.90% <100.00%> (ø)
workerintegration 58.53% <ø> (ø)
workerunit 90.37% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link
Copy Markdown

codecov-notifications Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 7, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing joebecher/fix-github-app-selection-order (69eea4b) with main (2e45f4f)

Open in CodSpeed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
def get_github_app_installations(owner: Owner | Any):
if _is_django_model(owner):
return owner.github_app_installations.all()
return owner.github_app_installations.order_by("id")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be ordered by now based off of models/core.py? my sqlalchemy is quite weak, so just going off of what I know of django orm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use either orm or sqlalchemy, not together. So we are not running order on the same dataset twice, which is what I think your concern is.

Copy link
Copy Markdown
Contributor

@thomasrockhu-codecov thomasrockhu-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to port this over to django ORM as well to keep consistency, but that's out of scope for this PR. I'd probably also add a test that changes the usage of the GitHubAppInstallations

@drazisil-codecov drazisil-codecov added this pull request to the merge queue May 8, 2026
Merged via the queue into main with commit 9164119 May 8, 2026
53 checks passed
@drazisil-codecov drazisil-codecov deleted the joebecher/fix-github-app-selection-order branch May 8, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants