Skip to content

Commit

Permalink
Bump adrf to 0.1.8 and aiohttp to 3.11.10 (#5275)
Browse files Browse the repository at this point in the history
  • Loading branch information
krysal authored Dec 16, 2024
1 parent d979b1c commit af38397
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 47 deletions.
4 changes: 2 additions & 2 deletions api/api/serializers/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers
from adrf.serializers import ModelSerializer


class BaseModelSerializer(serializers.ModelSerializer):
class BaseModelSerializer(ModelSerializer):
"""Extends model serializer to use docstring of properties as help text."""

def build_property_field(self, field_name, model_class):
Expand Down
4 changes: 3 additions & 1 deletion api/api/serializers/image_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from rest_framework import serializers

from adrf.serializers import Serializer

from api.constants.field_order import field_position_map
from api.constants.field_values import ASPECT_RATIOS, IMAGE_CATEGORIES, IMAGE_SIZES
from api.models import Image, ImageReport
Expand Down Expand Up @@ -96,7 +98,7 @@ class Meta:
##########################


class OembedRequestSerializer(serializers.Serializer):
class OembedRequestSerializer(Serializer):
"""Parse and validate oEmbed parameters."""

url = serializers.URLField(
Expand Down
9 changes: 5 additions & 4 deletions api/api/serializers/media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.exceptions import NotAuthenticated, ValidationError
from rest_framework.request import Request

from adrf.serializers import Serializer
from drf_spectacular.utils import extend_schema_serializer
from elasticsearch_dsl.response import Hit
from openverse_attribution.license import License
Expand Down Expand Up @@ -41,7 +42,7 @@
#######################


class PaginatedRequestSerializer(serializers.Serializer):
class PaginatedRequestSerializer(Serializer):
"""This serializer passes pagination parameters from the query string."""

_SUBJECT_TO_PAGINATION_LIMITS = (
Expand Down Expand Up @@ -549,7 +550,7 @@ def validate(self, data):
return data


class MediaThumbnailRequestSerializer(serializers.Serializer):
class MediaThumbnailRequestSerializer(Serializer):
"""This serializer parses and validates thumbnail query string parameters."""

full_size = serializers.BooleanField(
Expand Down Expand Up @@ -636,7 +637,7 @@ def _map_reason(self, value):
########################


class TagSerializer(serializers.Serializer):
class TagSerializer(Serializer):
"""This output serializer serializes a singular tag."""

name = serializers.CharField(
Expand Down Expand Up @@ -821,7 +822,7 @@ def to_representation(self, *args, **kwargs):


def get_hyperlinks_serializer(media_type):
class MediaHyperlinksSerializer(serializers.Serializer):
class MediaHyperlinksSerializer(Serializer):
"""
This serializer creates URLs pointing to other endpoints for this media item.
Expand Down
6 changes: 0 additions & 6 deletions api/api/utils/asyncio.py

This file was deleted.

4 changes: 2 additions & 2 deletions api/api/views/audio_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ async def get_image_proxy_media_info(self) -> image_proxy.MediaInfo:

@thumbnail_docs
@MediaViewSet.thumbnail_action
async def thumbnail(self, *args, **kwargs):
async def thumbnail(self, request, identifier):
"""
Retrieve the scaled down and compressed thumbnail of the artwork of an
audio track or its audio set.
"""
return await super().thumbnail(*args, **kwargs)
return await super().thumbnail(request)

@waveform
@action(
Expand Down
8 changes: 4 additions & 4 deletions api/api/views/image_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.conf import settings
from django.http.response import FileResponse, HttpResponse
from django.shortcuts import aget_object_or_404
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound
from rest_framework.response import Response
Expand Down Expand Up @@ -31,7 +32,6 @@
)
from api.utils import image_proxy
from api.utils.aiohttp import get_aiohttp_session
from api.utils.asyncio import aget_object_or_404
from api.utils.watermark import UpstreamWatermarkException, watermark
from api.views.media_views import MediaViewSet

Expand Down Expand Up @@ -102,7 +102,7 @@ async def oembed(self, request, *_, **__):
}

serializer = self.get_serializer(image, context=context)
return Response(data=serializer.data)
return Response(data=await serializer.adata)

async def get_image_proxy_media_info(self) -> image_proxy.MediaInfo:
image = await self.aget_object()
Expand All @@ -121,9 +121,9 @@ async def get_image_proxy_media_info(self) -> image_proxy.MediaInfo:

@thumbnail_docs
@MediaViewSet.thumbnail_action
async def thumbnail(self, *args, **kwargs):
async def thumbnail(self, request, identifier):
"""Retrieve the scaled down and compressed thumbnail of the image."""
return await super().thumbnail(*args, **kwargs)
return await super().thumbnail(request)

@watermark_doc
@action(detail=True, url_path="watermark", url_name="watermark")
Expand Down
7 changes: 2 additions & 5 deletions api/api/views/media_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from rest_framework.viewsets import ReadOnlyModelViewSet

import structlog
from adrf.views import APIView as AsyncAPIView
from adrf.generics import GenericAPIView as AsyncAPIView
from adrf.viewsets import ViewSetMixin as AsyncViewSetMixin
from asgiref.sync import sync_to_async

from api.constants.media_types import MediaType
from api.controllers import search_controller
Expand Down Expand Up @@ -87,8 +86,6 @@ def get_queryset(self):
)
)

aget_object = sync_to_async(ReadOnlyModelViewSet.get_object)

def get_serializer_context(self):
context = super().get_serializer_context()
req_serializer = self._get_request_serializer(self.request)
Expand Down Expand Up @@ -266,7 +263,7 @@ async def get_image_proxy_media_info(self) -> image_proxy.MediaInfo:
],
)

async def thumbnail(self, request, *_, **__):
async def thumbnail(self, request):
serializer = self.get_serializer(data=request.query_params)
serializer.is_valid(raise_exception=True)

Expand Down
42 changes: 21 additions & 21 deletions api/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ authors = [

requires-python = "==3.12.*"
dependencies = [
"adrf >=0.1.4, <0.2",
"aiohttp >=3.11.2, <4",
"adrf >= 0.1.8, <0.2",
"aiohttp >=3.11.10, <4",
"aws-requests-auth >=0.4.3, <0.5",
"deepdiff >=8.0.1, <9",
"django >=5.1.3, <6",
Expand Down

0 comments on commit af38397

Please sign in to comment.