Skip to content

Commit

Permalink
fix: encode NaN optical densities as null in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbock committed Mar 12, 2024
1 parent 678ed56 commit ea13552
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/antigenapi/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections.abc
import io
import math
import os
import urllib.error
import urllib.parse
Expand All @@ -23,6 +24,7 @@
FileField,
ModelSerializer,
PrimaryKeyRelatedField,
SerializerMethodField,
StringRelatedField,
ValidationError,
)
Expand Down Expand Up @@ -283,10 +285,18 @@ def perform_create(self, serializer): # noqa: D102
class NestedElisaWellSerializer(ModelSerializer):
"""A serializer for elisa wells."""

optical_density = SerializerMethodField()

class Meta: # noqa: D106
model = ElisaWell
exclude = ("id", "plate")

def get_optical_density(self, obj):
"""Get optical density - convert NaN to None for JSON encoding."""
if obj.optical_density is not None and not math.isnan(obj.optical_density):
return obj.optical_density
return None


class ElisaPlateSerializer(ModelSerializer):
"""A serializer for elisa plates.
Expand Down

0 comments on commit ea13552

Please sign in to comment.