Skip to content

'RelatedManager' object is not iterable #8726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
954-Ivory opened this issue Oct 24, 2022 · 4 comments
Closed

'RelatedManager' object is not iterable #8726

954-Ivory opened this issue Oct 24, 2022 · 4 comments
Labels

Comments

@954-Ivory
Copy link
Contributor

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.

@auvipy
Copy link
Member

auvipy commented Nov 21, 2022

good catch, lets continue on the PR

auvipy added a commit that referenced this issue Nov 22, 2022
* Fixes 'RelatedManager' object is not iterable in ListSerializer.to_representation.(#8726)

* Change to only BaseManager

* Commit unit test

* Update tests/test_serializer_lists.py

* Update tests/test_serializer_lists.py

* Update tests/test_serializer_lists.py

* Update tests/test_serializer_lists.py

* Update tests/test_serializer_lists.py

* Update tests/test_serializer_lists.py

* Format import

* Format import

Co-authored-by: Asif Saif Uddin <[email protected]>
@auvipy auvipy added the Bug label Nov 22, 2022
@auvipy auvipy closed this as completed Nov 22, 2022
@auvipy
Copy link
Member

auvipy commented Nov 22, 2022

thanks a lot for your contribution

@954-Ivory
Copy link
Contributor Author

thanks a lot for your contribution

I should thank you more to the teach and help 😀

@auvipy
Copy link
Member

auvipy commented Nov 22, 2022

and thank you for collaborating :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants