Skip to content

Commit

Permalink
CSV serializer to return None, for length if no end_date fixes mozill…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiftran committed Aug 21, 2020
1 parent 282d79f commit a19c95c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/experimenter/experiments/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class ExperimentCSVSerializer(serializers.ModelSerializer):
description = serializers.CharField(source="public_description")
hypothesis = serializers.CharField(source="objectives")
leading_indicators = serializers.CharField(source="analysis")
length = serializers.IntegerField(source="total_duration")
length = serializers.SerializerMethodField()
channel = serializers.CharField(source="firefox_channel")
enrolled_target = serializers.IntegerField(source="total_enrolled_clients")
locales = serializers.SerializerMethodField()
Expand Down Expand Up @@ -775,3 +775,7 @@ def get_locales(self, obj):

def get_countries(self, obj):
return ", ".join([country.name for country in obj.countries.order_by("name")])

def get_length(self, obj):
if obj.end_date:
return obj.total_duration
5 changes: 5 additions & 0 deletions app/experimenter/experiments/tests/api/v2/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,3 +2065,8 @@ def test_serializer_outputs_expected_schema(self):
"countries": f"{country1.name}, {country2.name}",
},
)
def test_serializer_outputs_no_length_for_exp_with_no_end_date(self):
experiment = ExperimentFactory.create(proposed_duration=None)
serializer = ExperimentCSVSerializer(experiment)
self.assertIsNone(serializer.data.get("length"))

0 comments on commit a19c95c

Please sign in to comment.