Re: Stop QuerySet repr from executing queries

2022-04-21 Thread Ian Foote
I've been working on the Kolo debugging tool and as part of that I've also run into this issue. Generating unexpected queries when monitoring a django project was a nasty surprise. In Kolo's case I was also able to work around it with a monkeypatch, but not needing this would be a nice performance

Re: Stop QuerySet repr from executing queries

2022-04-21 Thread 'Kevin Weaver' via Django developers (Contributions to Django itself)
I know this thread is more than a year old, but I was just bitten by this as well. We use the Elastic APM Python agent which, like Sentry, calls `repr()` on local variables that it sends as part of stack traces. We use Django REST Framework

Re: Stop QuerySet repr from executing queries

2021-03-23 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Would James' suggestion of reusing the result cache in __repr__ have solved your issue? I would like to see that first. I'm not against the DEBUG-only fetching but there hasn't been any suggestion what to show instead that could be of use. One can also mitigate against bad queries particularly we

Re: Stop QuerySet repr from executing queries

2021-03-23 Thread Joachim Jablon
Just been bitten by that same bug (combination of Sentry, using a Queryset.as_manager() that creates an unfiltered queryset as a local variable in the stack, a create signal that errored provoking a stacktrace that contained the queryset, a table that is always filtered by a field, and sorted b

Re: Stop QuerySet repr from executing queries

2021-03-06 Thread Michel Sabchuk
I agree with Matt on that. Avoiding executing the queries on production would be helpful! Let me share my case. I use django-rest-framework in a specific project and DRF has a feature: a serializer has a fancier string representation when printed. I was using a serializer with a queryset in a v

Re: Stop QuerySet repr from executing queries

2019-10-20 Thread Matt
Perhaps we ought to just keep the current behavior when DEBUG is True (it seems so obvious now, I can't believe it wasn't the first thing I suggested)? Django does lots of helpful things in DEBUG mode at the expense of performance. I think this would be an innocuous change for most people. It

Re: Stop QuerySet repr from executing queries

2019-10-16 Thread Mariusz Felisiak
W dniu środa, 16 października 2019 07:53:05 UTC+2 użytkownik Harro napisał: > > 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 situat

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread Harro
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? -- You received this message becaus

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread charettes
I agree with what James eloquently said, the issue is more complicated it appears. Simon Le mardi 15 octobre 2019 05:59:27 UTC-4, James Bennett a écrit : > > This request is a bit more complicated than I think people > realize. There's no practical way I can see to have the __repr__() of > a Que

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread James Bennett
This request is a bit more complicated than I think people realize. There's no practical way I can see to have the __repr__() of a QuerySet supply information sufficient to reconstruct it, at least not in a manner recognizable to most users of the ORM (there's no internal record of which query meth

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread 'Alexandr Aktsipetrov' via Django developers (Contributions to Django itself)
Current behavior is indeed usually useful but I actually remember being annoyed by it during interactive debugging - as watches affect sql log. What about reusing DEBUG instead of introducing brand new setting? I imagine all tutorials are in the context of scaffolded project with DEBUG=True a

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread Carlton Gibson
I'd be -1 on the change here too. That QuerySet shows you its value in the shell is beyond valuable. Look at the Django Tutorial , or the Django Girl Tutorial , or a

Re: Stop QuerySet repr from executing queries

2019-10-15 Thread Mariusz Felisiak
Hi y'all, I closed the original ticket because two responses is not enough to reopen it. I'm -1 to this change. IMO your issue is really niche and it's caused by multiple reasons, i.e. huge table, Meta.ordering by non-indexed column, uncaught exception, error reporting layer that calls `rep

Re: Stop QuerySet repr from executing queries

2019-10-14 Thread Matt
Created https://github.com/django/django/pull/11917 This patch will print the results of the query (if it has been evaluated). I did hit one odd case while writing the tests. Essentially, if you do: queryset = SomeModel.objects.all() list(queryset) SomeModel.objects.create(...) repr(queryset) T

Re: Stop QuerySet repr from executing queries

2019-10-11 Thread Ryan Hiebert
On Fri, Oct 11, 2019 at 9:29 PM Matt wrote: > I think it should just show instead of . > I agree, I think this makes the most sense. I think it can be argued that QuerySet should be consistent with [RawQuerySet, > which just uses a string of the query in the repr] > I can see the argument I s

Re: Stop QuerySet repr from executing queries

2019-10-11 Thread Matt
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 m

Re: Stop QuerySet repr from executing queries

2019-10-10 Thread Adam Johnson
I’m in favour of changing repr to not execute. Luke’s reasoning seems reasonable. On Thu, 10 Oct 2019 at 17:15, Ryan Hiebert wrote: > > > On Thu, Oct 10, 2019 at 10:50 AM Matt wrote: > >> >> I think we ought to reconsider the behavior of repr on QuerySets. I'm of >> the opinion that we should s

Re: Stop QuerySet repr from executing queries

2019-10-10 Thread Ryan Hiebert
On Thu, Oct 10, 2019 at 10:50 AM Matt wrote: > > 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 ki

Stop QuerySet repr from executing queries

2019-10-10 Thread Matt
repr(some_queryset) will execute the query and display some results from the query. This is done because it's (somewhat) helpful for debugging. https://github.com/django/django/blob/2a6f45e08e8cb8c7e5157915c378b453109424d2/django/db/models/query.py#L248 This has caused at least two people to sc