Skip to content

Commit f4bbb43

Browse files
authored
Remote repository: don't stop at first error while syncing (#12045)
In #12016 now all accounts from the same provider linked to the user are grouped together to do the sync, if one of those accounts fails to sync, we are skipping the rest of the accounts from the same provider.
1 parent a6defe0 commit f4bbb43

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

readthedocs/oauth/services/base.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,16 @@ def sync_user_access(cls, user):
163163
164164
:raises SyncServiceError: if the access token is invalid or revoked
165165
"""
166+
has_error = False
166167
for service in cls.for_user(user):
167-
service.sync()
168+
try:
169+
service.sync()
170+
except SyncServiceError:
171+
# Don't stop the sync if one service account fails,
172+
# as we should try to sync all accounts.
173+
has_error = True
174+
if has_error:
175+
raise SyncServiceError()
168176

169177
@cached_property
170178
def session(self):

readthedocs/rtd_tests/tests/test_oauth_tasks.py

+20
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,23 @@ def test_sync_remote_repository_organizations_without_slugs(
116116
args=[self.user.pk],
117117
countdown=0,
118118
)
119+
120+
@patch("readthedocs.oauth.services.github.GitHubService.sync")
121+
@patch("readthedocs.oauth.services.gitlab.GitLabService.sync")
122+
@patch("readthedocs.oauth.services.bitbucket.BitbucketService.sync")
123+
def test_sync_dont_stop_if_one_service_account_of_same_type_fails(
124+
self, sync_bb, sync_gl, sync_gh
125+
):
126+
get(
127+
SocialAccount,
128+
user=self.user,
129+
provider=GitHubOAuth2Adapter.provider_id,
130+
)
131+
sync_gh.side_effect = SyncServiceError
132+
r = sync_remote_repositories(self.user.pk)
133+
assert "GitHub" in r["error"]
134+
assert "Bitbucket" not in r["error"]
135+
assert "GitLab" not in r["error"]
136+
sync_bb.assert_called_once()
137+
sync_gl.assert_called_once()
138+
assert sync_gh.call_count == 2

0 commit comments

Comments
 (0)