Skip to content
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

Handle models without .objects manager in ModelSerializer. #6111

Merged
merged 2 commits into from Aug 6, 2018

Conversation

K0Te
Copy link
Contributor

@K0Te K0Te commented Aug 6, 2018

This pull request is a proposed fix for #6110 .
Regression test-case is added.
Alternative solution is to use Model._default_manager, but current solution seems more simple.

@carltongibson
Copy link
Collaborator

carltongibson commented Aug 6, 2018

Alternative solution is to use Model._default_manager...

I think that would be better.

@codecov-io
Copy link

codecov-io commented Aug 6, 2018

Codecov Report

Merging #6111 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #6111      +/-   ##
==========================================
+ Coverage   96.17%   96.17%   +<.01%     
==========================================
  Files         128      128              
  Lines       17599    17610      +11     
  Branches     1459     1459              
==========================================
+ Hits        16926    16937      +11     
  Misses        465      465              
  Partials      208      208

@K0Te
Copy link
Contributor Author

K0Te commented Aug 6, 2018

Hi @carltongibson, thanks for prompt review !
I've re-implemented same fix using Model._default_manager

Copy link
Collaborator

@carltongibson carltongibson left a comment

OK. Yes. This looks good to me. The use-case should be supported.

@carltongibson carltongibson added this to the 3.9 Release milestone Aug 6, 2018
@carltongibson carltongibson merged commit 8b5e830 into encode:master Aug 6, 2018
1 check passed
@carltongibson
Copy link
Collaborator

carltongibson commented Aug 6, 2018

Thanks @K0Te!

@rpkilby
Copy link
Member

rpkilby commented Aug 6, 2018

Should we use the manager's name instead of ._default_manager?

@carltongibson
Copy link
Collaborator

carltongibson commented Aug 6, 2018

No, I don’t think so. (How would you do that? Default manager just picks the first manager defined on the class. Normally that’s “objects”, but people do all sorts of things...)

@rpkilby
Copy link
Member

rpkilby commented Aug 6, 2018

Managers should have a .name attribute if I'm not mistaken. So, you'd just template in Model._default_manager.name instead of using the hardcoded string.

@K0Te
Copy link
Contributor Author

K0Te commented Aug 6, 2018

Model._default_manager.name should work fine.
I'll open new PR with these improvements.

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Handle models without .objects manager in ModelSerializer.

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

Successfully merging this pull request may close these issues.

None yet

4 participants