Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return a throttled response if org is being synced for the first time during auth #5374

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
3 changes: 3 additions & 0 deletions engine/apps/auth_token/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ def get_organization(self, request, auth):
# if organization exists, we are good)
setup_organization(url, auth)
organization = Organization.objects.filter(grafana_url=url).first()
if organization is None:
# sync may still be in progress, client should retry
raise exceptions.Throttled(detail="Organization being synced, please retry.")
return organization

if settings.LICENSE == settings.CLOUD_LICENSE_NAME:
Expand Down
4 changes: 2 additions & 2 deletions engine/apps/auth_token/tests/test_grafana_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def test_grafana_authentication_no_org_grafana_url():
request_sync_url = f"{grafana_url}/api/plugins/{PluginID.ONCALL}/resources/plugin/sync?wait=true&force=true"
httpretty.register_uri(httpretty.POST, request_sync_url, status=404)

with pytest.raises(exceptions.AuthenticationFailed) as exc:
with pytest.raises(exceptions.Throttled) as exc:
GrafanaServiceAccountAuthentication().authenticate(request)
assert exc.value.detail == "Organization not found."
assert exc.value.detail == "Organization being synced, please retry."


@pytest.mark.parametrize("grafana_url", ["null;", "foo", ""])
Expand Down
Loading