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

Prefetch Serialization: Add a preference during mapping #10933

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
12 changes: 11 additions & 1 deletion dojo/api_v2/prefetch/prefetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

from rest_framework.serializers import ModelSerializer

from dojo.models import FileUpload

from . import utils

# Reduce the scope of search for serializers.
SERIALIZER_DEFS_MODULE = "dojo.api_v2.serializers"

preferred_serializers = {
FileUpload: "FileSerializer",
}


class _Prefetcher:
@staticmethod
Expand All @@ -31,7 +37,11 @@ def _is_model_serializer(obj):

for _, serializer in available_serializers:
model = serializer.Meta.model
serializers[model] = serializer
if model in preferred_serializers:
if serializer.__name__ == preferred_serializers[model]:
serializers[model] = serializer
else:
serializers[model] = serializer
# We add object->None to have a more uniform processing later on
serializers[object] = None

Expand Down
Loading