Skip to content

Commit

Permalink
Prevent duplicate serialization of dandiset
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Jan 2, 2025
1 parent a53e3bf commit 50f6c9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
30 changes: 1 addition & 29 deletions dandiapi/api/tests/test_dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,6 @@ def test_dandiset_rest_create(api_client, user):
'asset_count': 0,
'active_uploads': 0,
'size': 0,
'dandiset': {
'identifier': DANDISET_ID_RE,
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
'contact_person': 'Doe, John',
'embargo_status': 'OPEN',
},
'status': 'Pending',
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
Expand Down Expand Up @@ -454,13 +447,6 @@ def test_dandiset_rest_create_with_identifier(api_client, admin_user):
'asset_count': 0,
'active_uploads': 0,
'size': 0,
'dandiset': {
'identifier': identifier,
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
'contact_person': 'Doe, John',
'embargo_status': 'OPEN',
},
'status': 'Pending',
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
Expand Down Expand Up @@ -562,13 +548,6 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user):
'asset_count': 0,
'active_uploads': 0,
'size': 0,
'dandiset': {
'identifier': identifier,
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
'contact_person': 'Jane Doe',
'embargo_status': 'OPEN',
},
'status': 'Pending',
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
Expand Down Expand Up @@ -653,13 +632,6 @@ def test_dandiset_rest_create_embargoed(api_client, user):
'asset_count': 0,
'active_uploads': 0,
'size': 0,
'dandiset': {
'identifier': DANDISET_ID_RE,
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
'contact_person': 'Doe, John',
'embargo_status': 'EMBARGOED',
},
'status': 'Pending',
'created': TIMESTAMP_RE,
'modified': TIMESTAMP_RE,
Expand Down Expand Up @@ -1115,7 +1087,7 @@ def test_dandiset_contact_person_malformed_contributors(api_client, draft_versio
f'/api/dandisets/{draft_version.dandiset.identifier}/',
)

assert results.data['draft_version']['dandiset']['contact_person'] == ''
assert results.data['contact_person'] == ''


@pytest.mark.django_db
Expand Down
10 changes: 8 additions & 2 deletions dandiapi/api/views/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class Meta:
dandiset = DandisetSerializer()
# name = serializers.SlugRelatedField(read_only=True, slug_field='name')

def __init__(self, *args, **kwargs):
if kwargs.get('context', {}).get('child', False):
del self.fields['dandiset']

super().__init__(*args, **kwargs)


class DandisetVersionSerializer(serializers.ModelSerializer):
"""The version serializer nested within the Dandiset Serializer."""
Expand Down Expand Up @@ -174,8 +180,8 @@ class DandisetDetailSerializer(DandisetSerializer):
class Meta(DandisetSerializer.Meta):
fields = [*DandisetSerializer.Meta.fields, 'most_recent_published_version', 'draft_version']

most_recent_published_version = VersionSerializer(read_only=True)
draft_version = VersionSerializer(read_only=True)
most_recent_published_version = VersionSerializer(read_only=True, context={'child': True})
draft_version = VersionSerializer(read_only=True, context={'child': True})


class DandisetQueryParameterSerializer(serializers.Serializer):
Expand Down

0 comments on commit 50f6c9a

Please sign in to comment.