Skip to content

Commit e7dcee8

Browse files
authored
fix(gitlab): Copy immutable querydict before modifying (#59130)
In this PR #58679, I refactored some code. I didn't realize that Django query parameters are stored as a QueryDict which is immutable. To fix it I make a copy before modifying. Also change argument types from `MutableMapping` -> `Mapping` ### In Action https://github.com/getsentry/sentry/assets/67301797/e0af4d2c-8a84-480c-8071-699987b95ad6 Resolves #59092
1 parent c81e326 commit e7dcee8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/sentry/integrations/gitlab/issues.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Any, Dict, List, MutableMapping, Sequence
2+
from typing import Any, Dict, List, Mapping, Sequence
33

44
from django.urls import reverse
55

@@ -24,11 +24,13 @@ def get_issue_url(self, key):
2424
def get_persisted_default_config_fields(self) -> Sequence[str]:
2525
return ["project"]
2626

27-
def get_projects_and_default(self, group: Group, params: MutableMapping[str, Any], **kwargs):
27+
def get_projects_and_default(self, group: Group, params: Mapping[str, Any], **kwargs):
2828
defaults = self.get_project_defaults(group.project_id)
2929

3030
# XXX: In GitLab repositories are called projects but get_repository_choices
3131
# expects the param to be called 'repo', so we need to rename it here.
32+
# Django QueryDicts are immutable, so we need to copy it first.
33+
params = params.copy()
3234
params["repo"] = params.get("project") or defaults.get("project")
3335

3436
default_project, project_choices = self.get_repository_choices(group, params, **kwargs)

src/sentry/integrations/mixins/issues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from collections import defaultdict
66
from copy import deepcopy
7-
from typing import Any, ClassVar, Dict, List, Mapping, MutableMapping, Sequence
7+
from typing import Any, ClassVar, Dict, List, Mapping, Sequence
88

99
from sentry.integrations.utils import where_should_sync
1010
from sentry.models.group import Group
@@ -268,7 +268,7 @@ def get_issue_display_name(self, external_issue):
268268
"""
269269
return ""
270270

271-
def get_repository_choices(self, group: Group, params: MutableMapping[str, Any], **kwargs):
271+
def get_repository_choices(self, group: Group, params: Mapping[str, Any], **kwargs):
272272
"""
273273
Returns the default repository and a set/subset of repositories of associated with the installation
274274
"""

0 commit comments

Comments
 (0)