... you have a conflict between the goal of being information rich and with always being useful for debugging. In general, automatically seeing the results is information rich and is useful in debugging, but sometimes it causes further problems.
I have thought about it, and with this conflict of goals, I think we are going to have to err on the side of the current behaviour. It is possible to work around by not callingrepr
onQuerySets
in your middleware, and there are too many people who will be upset (or have problems with their own debugging facilities) by changing this.
>>> f = open("foo.py")
>>> repr(f)
"<_io.TextIOWrapper name='foo.py' mode='r' encoding='UTF-8'>"
>>>
I think we ought to reconsider the behavior of repr on QuerySets. I'm of the opinion that we should scrap it completely. It could be replaced by something that generates the SQL that would be executed (although that may be tricky), or some kind of representation of the query filter.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABpHFHS1%3DirRaQVWgiUnmTX%2By%3DB7Vy%2BpGLha-aoYmqTGUSj20g%40mail.gmail.com.
I reviewed the patch that was originally created for this:
https://github.com/django/django/pull/1055/commits/7d53d428c0323a7eca93b7b56968a895b031e2ae
Essentially, it only includes the results of the queryset in the repr *if* the QuerySet._result_cache has been populated. There is one minor thing I don't like about the particular implementation: it shows the empty list if the result cache is not populated. I think it should just show <QuerySet> instead of <QuerySet []>. That way you can differentiate between _result_cache=None, and _result_cache=[].
This is an OK approach, but the inconsistency in the representation smells a little off.
RawQuerySet simply does:
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.query)
which is dead simple, and useful. I think it can be argued that QuerySet should be consistent with it (otherwise, why isn't RawQuerySet executing its SQL to show the repr?)
Regarding other things that have been mentioned: I'm not too keen about introducing a setting for this behavior, or doing things differently in an interactive console. Django already has a lot of settings, and this seems like such a minor thing. And I don't know of any precedent for changing the behavior of Django in an interactive shell (and you can tell I'm not a fan of inconsistent behaviors).
I'm going to re-open the ticket and hope other Django devs chime in.
I think it should just show <QuerySet> instead of <QuerySet []>.
I think it can be argued that QuerySet should be consistent with [RawQuerySet, which just uses a string of the query in the repr]
Regarding other things that have been mentioned: I'm not too keen about introducing a setting for this behavior, or doing things differently in an interactive console. Django already has a lot of settings, and this seems like such a minor thing. And I don't know of any precedent for changing the behavior of Django in an interactive shell (and you can tell I'm not a fan of inconsistent behaviors).
I'm -1 to this change. ... to be honest even with all of this fetching the first 20 rows should not crash your production database... I'm against this change because it will have a negative impact for most of users ...It will also have a big impact on our documentation ~ 200 examples to change.
Having the query evaluated during debugging has been shown to be harmful in certain situations, isn't that the most important thing to fix?
Yes, it's a complicated issue, but isn't the SQL query the ultimate representation of which methods are called or not?Having the query evaluated during debugging has been shown to be harmful in certain situations, isn't that the most important thing to fix?
It is not the most important thing to remove behavior that most of users use because we want to fix an edge case that was reported twice in the last six years.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/050a8686-eaa5-47e7-a9ab-d8dd6fd14844n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/00cabdaf-c9ef-4403-b43a-8d50eeffa42an%40googlegroups.com.