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

ref: fix signature overrides for most Serializers #74677

Merged
merged 1 commit into from
Jul 23, 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
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ActivitySerializer(Serializer):
def __init__(self, environment_func=None):
self.environment_func = environment_func

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
# TODO(dcramer); assert on relations
user_ids = [i.user_id for i in item_list if i.user_id]
user_list = user_service.serialize_many(
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_attrs(self, item_list, user):
for item in item_list
}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
if obj.type == ActivityType.SET_RESOLVED_IN_COMMIT.value:
data = {"commit": attrs["commit"]}
elif obj.type == ActivityType.SET_RESOLVED_IN_PULL_REQUEST.value:
Expand All @@ -120,7 +120,7 @@ def serialize(self, obj, attrs, user):


class OrganizationActivitySerializer(ActivitySerializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
from sentry.api.serializers import GroupSerializer

# TODO(dcramer); assert on relations
Expand All @@ -142,7 +142,7 @@ def get_attrs(self, item_list, user):
attrs[item]["project"] = projects[str(item.project_id)]
return attrs

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
context = super().serialize(obj, attrs, user)
context["issue"] = attrs["issue"]
context["project"] = attrs["project"]
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/apiapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@register(ApiApplication)
class ApiApplicationSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
is_secret_visible = obj.date_added > timezone.now() - timedelta(days=1)
return {
"id": obj.client_id,
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/serializers/models/apiauthorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@register(ApiAuthorization)
class ApiAuthorizationSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
apps = {
d["id"]: d
for d in serialize({i.application for i in item_list if i.application_id}, user)
Expand All @@ -17,7 +17,7 @@ def get_attrs(self, item_list, user):
}
return attrs

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id),
"scopes": obj.get_scopes(),
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/apikey.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@register(ApiKey)
class ApiKeySerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id),
"label": obj.label,
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/artifactbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _compute_associations(item, grouped_bundles):
def _format_date(date):
return None if date is None else date.isoformat()[:19] + "Z"

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
# We sort by id, since it's the best (already existing) field to define total order of
# release associations that is somehow consistent with upload sequence.
release_artifact_bundles = ReleaseArtifactBundle.objects.filter(
Expand All @@ -45,7 +45,7 @@ def get_attrs(self, item_list, user):
for item in item_list
}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"bundleId": str(attrs["bundle_id"]),
"associations": attrs["associations"],
Expand All @@ -60,7 +60,7 @@ def __init__(self, archive, *args, **kwargs):
Serializer.__init__(self, *args, **kwargs)
self.archive = archive

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
return {item: self._compute_attrs(item) for item in item_list}

def _compute_attrs(self, item):
Expand All @@ -80,7 +80,7 @@ def _compute_attrs(self, item):
"sourcemap": sourcemap,
}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": base64.urlsafe_b64encode(attrs["file_path"].encode()).decode(),
# In case the file type string was invalid, we return the sentinel value INVALID_SOURCE_FILE_TYPE.
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/serializers/models/auditlogentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def override_actor_id(user):

@register(AuditLogEntry)
class AuditLogEntrySerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
# TODO(dcramer); assert on relations
prefetch_related_objects(item_list, "actor")
prefetch_related_objects(item_list, "target_user")
Expand All @@ -57,7 +57,7 @@ def get_attrs(self, item_list, user):
for item in item_list
}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
audit_log_event = audit_log.get(obj.event)

try:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/serializers/models/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@register(AuthenticatorInterface)
class AuthenticatorInterfaceSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
data = {
"id": str(obj.interface_id),
"name": obj.name,
Expand Down Expand Up @@ -37,7 +37,7 @@ def serialize(self, obj, attrs, user):

@register(SmsInterface)
class SmsInterfaceSerializer(AuthenticatorInterfaceSerializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
data = super().serialize(obj, attrs, user)
data["phone"] = obj.phone_number
return data
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@register(Broadcast)
class BroadcastSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
if not user.is_authenticated:
seen = set()
else:
Expand All @@ -18,7 +18,7 @@ def get_attrs(self, item_list, user):

return {item: {"seen": item.id in seen} for item in item_list}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id),
"message": obj.message,
Expand All @@ -33,7 +33,7 @@ def serialize(self, obj, attrs, user):


class AdminBroadcastSerializer(BroadcastSerializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
attrs = super().get_attrs(item_list, user)
counts = dict(
BroadcastSeen.objects.filter(broadcast__in=item_list)
Expand All @@ -47,7 +47,7 @@ def get_attrs(self, item_list, user):
attrs[item]["user_count"] = counts.get(item.id, 0)
return attrs

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
context = super().serialize(obj, attrs, user)
context["userCount"] = attrs["user_count"]
return context
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, exclude=None, include=None, type=None, *args, **kwargs):
self.exclude = frozenset(exclude if exclude else ())
self.type = type or ""

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
if "author" not in self.exclude:
users_by_author = get_users_for_commits(item_list, user)
else:
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_attrs(self, item_list, user):

return result

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
d = {
"id": obj.key,
"message": obj.message,
Expand All @@ -85,7 +85,7 @@ def __init__(self, exclude=None, include=None, type=None, *args, **kwargs):
self.exclude = frozenset(exclude if exclude else ())
self.type = type or ""

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
from sentry.models.releasecommit import ReleaseCommit

attrs = super().get_attrs(item_list, user)
Expand All @@ -99,7 +99,7 @@ def get_attrs(self, item_list, user):
attrs[item]["releases"] = releases_by_commit[item.id]
return attrs

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
data = super().serialize(obj, attrs, user)
data["releases"] = [
{
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@register(DashboardWidget)
class DashboardWidgetSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
result = {}
data_sources = serialize(
list(
Expand Down Expand Up @@ -82,7 +82,7 @@ def serialize(self, obj, attrs, user, **kwargs):

@register(DashboardWidgetQuery)
class DashboardWidgetQuerySerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
result = {}

stateful_extraction_version = (
Expand Down Expand Up @@ -122,7 +122,7 @@ def serialize(self, obj, attrs, user, **kwargs):


class DashboardListSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
item_dict = {i.id: i for i in item_list}

widgets = (
Expand Down Expand Up @@ -183,7 +183,7 @@ def serialize(self, obj, attrs, user, **kwargs):

@register(Dashboard)
class DashboardDetailsSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
result = {}

widgets = serialize(
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/debug_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@register(ProjectDebugFile)
class DebugFileSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
d = {
"id": str(obj.id),
"uuid": obj.debug_id[:36],
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/discoversavedquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@register(DiscoverSavedQuery)
class DiscoverSavedQuerySerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
result: DefaultDict[str, dict] = defaultdict(lambda: {"created_by": {}})

service_serialized = user_service.serialize_many(
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/api/serializers/models/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

@register(Environment)
class EnvironmentSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {"id": str(obj.id), "name": obj.name}


@register(EnvironmentProject)
class EnvironmentProjectSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id),
"name": obj.environment.name,
Expand All @@ -38,7 +38,7 @@ def __init__(self, group, since=None, until=None):
self.since = since
self.until = until

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
attrs = {item: {"stats": {}} for item in item_list}
items = {self.group.id: []}
for item in item_list:
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_attrs(self, item_list, user):
]
return attrs

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
result = super().serialize(obj, attrs, user)
result["stats"] = attrs["stats"]
return result
12 changes: 6 additions & 6 deletions src/sentry/api/serializers/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def should_display_error(self, error):
and ".frames." not in name
)

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
from sentry.api.serializers.rest_framework import convert_dict_key_case, snake_to_camel_case

errors = [
Expand Down Expand Up @@ -468,10 +468,10 @@ def serialize(self, obj, attrs, user, include_full_release_data=False):


class SharedEventSerializer(EventSerializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
return super().get_attrs(item_list, user, is_public=True)

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
result = super().serialize(obj, attrs, user)
del result["context"]
del result["contexts"]
Expand All @@ -497,15 +497,15 @@ class SimpleEventSerializer(EventSerializer):
organization event search API gets real slow.
"""

def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
crash_files = get_crash_files(item_list)
serialized_files = {
file.event_id: serialized
for file, serialized in zip(crash_files, serialize(crash_files, user=user))
}
return {event: {"crash_file": serialized_files.get(event.event_id)} for event in item_list}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
tags = [{"key": key.split("sentry:", 1)[-1], "value": value} for key, value in obj.tags]
for tag in tags:
query = convert_user_tag_to_query(tag["key"], tag["value"])
Expand Down Expand Up @@ -542,7 +542,7 @@ class ExternalEventSerializer(EventSerializer):
should be used for Integrations that need to include event data.
"""

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
from sentry.notifications.utils import get_notification_group_title

tags = [{"key": key.split("sentry:", 1)[-1], "value": value} for key, value in obj.tags]
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/eventattachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_attrs(self, item_list, user, **kwargs):
}
return {ea: {"file": files[ea.file_id]} for ea in item_list if ea.file_id}

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
file = attrs.get("file")
content_type = obj.content_type or get_mimetype(file)
size = obj.size if obj.size is not None else file.size
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/eventuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@register(EventUser)
class EventUserSerializer(Serializer):
def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id) if obj.id is not None else obj.id,
"tagValue": obj.tag_value,
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/serializers/models/filechange.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@register(CommitFileChange)
class CommitFileChangeSerializer(Serializer):
def get_attrs(self, item_list, user):
def get_attrs(self, item_list, user, **kwargs):
commits = list(
Commit.objects.filter(id__in=[f.commit_id for f in item_list]).select_related("author")
)
Expand All @@ -35,7 +35,7 @@ def get_attrs(self, item_list, user):

return result

def serialize(self, obj, attrs, user):
def serialize(self, obj, attrs, user, **kwargs):
return {
"id": str(obj.id),
"orgId": obj.organization_id,
Expand Down
Loading
Loading