Skip to content

'RelatedManager' object is not iterable #8726

Closed
@954-Ivory

Description

@954-Ivory

These days, I create a custom manager repr for django:

https://github.com/954-Ivory/django_bulk_hook_manager

But I get the error when I use it with DRF:

rest_framework/serializers.py", line 686, in to_representation
    return [
TypeError: 'RelatedManager' object is not iterable

So, I check it, and found the reason.


Error line:

iterable = data.all() if isinstance(data, models.Manager) else data

This line should change to:

iterable = data.all() if isinstance(data, (
            models.manager.Manager, models.manager.BaseManager
        )) else data

We need to check whether data is a BaseManager instance.

I will PR later.

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