Skip to content

Serializers with many=True should return empty list rather than empty dict #3434

@nip3o

Description

@nip3o

A serializer with many=True returns a list of dicts when accessing serializer.errors or serializer.validated_data. If these are empty, however, an empty dict is returned (just as when many=False). I believe that it would be more consistent to return an empty list in this case.

Example test case: https://github.com/tomchristie/django-rest-framework/compare/tomchristie:master...nip3o:empty-errors?expand=1

==================================================================================== FAILURES ====================================================================================
_______________________________________________________________ BulkCreateSerializerTests.test_bulk_create_errors ________________________________________________________________
tests/test_serializer_bulk_update.py:80: in test_bulk_create_errors
    self.assertEqual(serializer.validated_data, [])
E   AssertionError: {} != []
_______________________________________________________________ BulkCreateSerializerTests.test_bulk_create_success _______________________________________________________________
tests/test_serializer_bulk_update.py:49: in test_bulk_create_success
    self.assertEqual(serializer.errors, [])
E   AssertionError: {} != []
================================================================ 2 failed, 743 passed, 2 warnings in 7.98 seconds ===============================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy