Skip to content

Commit

Permalink
hotfix: avoid double inserts when sync_repos (#412)
Browse files Browse the repository at this point in the history
Sync_repos when the repos affected are knows is acting up.
Unsure if it's the filtering logic OR a race condition OR if something else
is inserting the repo.

We will be moving to `upsert_repo` to avoid this issue.
  • Loading branch information
giovanni-guidini committed Apr 24, 2024
1 parent 5d85174 commit bcec347
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tasks/sync_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,28 @@ async def sync_repos_affected_repos_known(
async for repo_data in git.get_repos_from_nodeids_generator(
repos_to_search, owner.username
):
# Insert those repos
new_repo = Repository(
service_id=repo_data["service_id"],
name=repo_data["name"],
language=repo_data["language"],
private=repo_data["private"],
branch=repo_data["branch"],
using_integration=True,
)
# Get or create owner
if repo_data["owner"]["is_expected_owner"]:
new_repo.ownerid = owner.ownerid
new_repo_ownerid = owner.ownerid
else:
upserted_owner_id = self.upsert_owner(
db_session,
git.service,
repo_data["owner"]["service_id"],
repo_data["owner"]["username"],
)
new_repo.ownerid = upserted_owner_id
db_session.add(new_repo)
db_session.flush()
repoids_added.append(new_repo.repoid)
new_repo_ownerid = upserted_owner_id
# Get or create repo
# Yes we had issues trying to insert a repeated repo at this point.
# Maybe race condition?
repoid = self.upsert_repo(
db_session=db_session,
service=git.service,
ownerid=new_repo_ownerid,
repo_data={**repo_data, "service_id": str(repo_data["service_id"])},
using_integration=True,
)
repoids_added.append(repoid)
return repoids_added

def _possibly_update_ghinstallation_covered_repos(
Expand Down

0 comments on commit bcec347

Please sign in to comment.