Skip to content

Commit

Permalink
series: Protect the serializers from last_revision being None
Browse files Browse the repository at this point in the history
While, in theory, there shouldn't be any series without a revision,
the parsing code has a small problem creating series out of normal mail
threads (yes, that need to be fixed!). This causes internal errors so we
need to be a bit defensive while waiting for the real fix.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Jan 26, 2016
1 parent bae1fc6 commit 4681598
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions patchwork/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,23 @@ class Meta:
fields = ('id', 'name')

class SeriesSerializer(PatchworkModelSerializer):
version = serializers.IntegerField(source='last_revision.version',
read_only=True)
n_patches = serializers.IntegerField(source='last_revision.n_patches',
read_only=True)
version = serializers.SerializerMethodField('get_version')
n_patches = serializers.SerializerMethodField('get_n_patches')
test_state = serializers.SerializerMethodField('get_test_state')

def get_version(self, obj):
if not obj.last_revision:
return 1
return obj.last_revision.version

def get_n_patches(self, obj):
if not obj.last_revision:
return 0
return obj.last_revision.n_patches

def get_test_state(self, obj):
if not obj.last_revision:
return None
state = obj.last_revision.test_state
if state is not None:
return dict(TestState.STATE_CHOICES)[state]
Expand Down

0 comments on commit 4681598

Please sign in to comment.