Possible bug - defer in a Model Manager

35 views
Skip to first unread message

David Burke

unread,
Aug 27, 2015, 11:26:19 AM8/27/15
to django...@googlegroups.com
Hello,

I had a use case where I wanted to defer a field by default. I used the get_queryset function in the manger like this to make it always happen.

def get_queryset(self):
        return super().get_queryset().defer('bigfield')

It seems to work, however it introduces some very strange side effects by changing the class name as described here. I would get errors like 

TemplateDoesNotExist: my_app/my_model_deferred_bigfield_detail.html

Clearly class based views are getting confused by the Model class name. Before I report a bug I wanted some general thoughts on the matter. Am I abusing the get_queryset method in my manager? 

I had some issues from other apps too like django-activity-stream. Presumably a common way of generates model names isn't working with defer.

Tim Graham

unread,
Aug 27, 2015, 11:48:19 AM8/27/15
to Django users
Usually code needs to be adapted to work with deferred models. The class-based view issue you mentioned could be this fix for DetailView:

https://github.com/django/django/commit/86aaffa5a3510c007167d116cf4ad72b79e93f31

(fixed in Django 1.9). If not, please open a bug if the issue can be reproduced on master.
Reply all
Reply to author
Forward
0 new messages