Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions apps/codecov-api/webhook_handlers/views/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,32 @@ def post(self, request, *args, **kwargs):

try:
# all other events should correspond to a repo in the db
repo = get_object_or_404(
Repository, author__service=self.service_name, service_id=project_id
)
# Filter out repositories owned by accounts with None usernames
# to avoid MultipleObjectsReturned errors
repos = Repository.objects.filter(
author__service=self.service_name, service_id=project_id
).exclude(author__username=None)

if repos.count() == 0:
# If no valid repos found, try without the exclusion
# This handles the case where the only repo has a None username owner
repo = get_object_or_404(
Repository, author__service=self.service_name, service_id=project_id
)
elif repos.count() == 1:
repo = repos.first()
else:
# Multiple valid repositories found - log and return the first one
log.warning(
"Multiple repositories found for service_id",
extra={
"service": self.service_name,
"service_id": project_id,
"repo_count": repos.count(),
"repo_ids": list(repos.values_list("repoid", flat=True)),
},
)
repo = repos.first()
except Exception as e:
self._inc_err("repo_not_found")
raise e
Expand Down
12 changes: 12 additions & 0 deletions apps/worker/tasks/sync_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def run_impl(self, db_session, ownerid, *, username=None, **kwargs):
updated_teams = []

for team in teams:
# Skip teams with None username to prevent creating invalid Owner records
if team.get("username") is None:
log.warning(
"Skipping team with None username",
extra={
"service": service,
"team_id": team.get("id"),
"team_name": team.get("name"),
},
)
continue

team_data = {
"username": team["username"],
"name": team["name"],
Expand Down
1 change: 1 addition & 0 deletions libs/shared/shared/torngit/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ async def list_teams(self, token=None):
"parent_id": g["parent_id"],
}
for g in groups
if g.get("full_path") # Filter out groups with null/missing full_path
]
)
return all_groups
Expand Down
Loading