I'm sorry for not being polite. Believe my I love what you have built already and what to support in any way I can.
My question is exactly what is in the subject is, it is not some kind of clickbait. I've done some research before, and I understand the complexity of the task you want to accomplish in the linked ticket. My question and concerns are more about - why we have it in the first place. If the intention is to debug rather than using in production - we can change the function in a way I suggested above, and no need to close the linked ticket at all. The problem with the function is that it is actually working, but not always, and because of that, other people are suggesting it on StackOverflow, using it in prod, and may, eventually catch weird exceptions, which leads to a bad experience with Django in general. Also, want to say it again, English is not my first language, and some words may sound not polite at all. It is not my intention, I respect all the work you have done with Django, and very thankful for continue working on it. On Thursday, September 10, 2020 at 11:36:04 AM UTC+3 Adam Johnson wrote: > What the purpose of having function that is not working correctly? >> > > You'll go further in life if you use more descriptive, less inflammatory > subjects. > > Also it's polite to search the ticket tracker for related issues before > posting on the list. This is the relevant ticket: > https://code.djangoproject.com/ticket/25705 > > Query.__str__ has never been intended as more than a debugging aid. Part > of the reason it's hard to compute the *actual* SQL is because Django > doesn't do it - it's done by the database library on cursor.execute(). This > is more than string quoting - some objects have special adapters, for > example JSON values. On top of this, there's no standard method in the > database libraries for SQL interpolation - it was never specified in DB API > ( https://www.python.org/dev/peps/pep-0249/ ). > > psycopg2 has a mogrify() function, but the other libarries don't - it may > require calling some internal/undocumented methods. Solving this ticket > needs some research and work. Your contributions would be welcome. > > On Thu, 10 Sep 2020 at 09:15, Alexander Lyabah <a.ly...@checkio.org> > wrote: > >> >> What the purpose of having function that is not working correctly, when >> you may not have this function at all and thing is changed. >> >> I'm talking here about function Query.__str__ >> >> Bellow I show you an example: >> >> In [19]: str(TimelineEvent.objects.filter(id__gt=100).query) >> Out[19]: 'SELECT "timeline_timelineevent"."id", >> "timeline_timelineevent"."created_on", >> "timeline_timelineevent"."modified_on", >> "timeline_timelineevent"."action_on", >> "timeline_timelineevent"."timeline_id", >> "timeline_timelineevent"."content_type_id", >> "timeline_timelineevent"."object_id", "timeline_timelineevent"."action", >> "timeline_timelineevent"."meta" FROM "timeline_timelineevent" WHERE >> "timeline_timelineevent"."id" > 100 ORDER BY >> "timeline_timelineevent"."action_on" DESC, "timeline_timelineevent"."id" >> DESC' >> In [20]: Timeline.objects.raw(str(TimelineEvent.objects.filter(id__gt=100 >> ).query)) >> Out[20]: <RawQuerySet: SELECT "timeline_timelineevent"."id", >> "timeline_timelineevent"."created_on", "timeline_timelineevent". >> "modified_on", "timeline_timelineevent"."action_on", >> "timeline_timelineevent"."timeline_id", "timeline_timelineevent". >> "content_type_id", "timeline_timelineevent"."object_id", >> "timeline_timelineevent"."action", "timeline_timelineevent"."meta" FROM >> "timeline_timelineevent" WHERE "timeline_timelineevent"."id" > 100 ORDER >> BY "timeline_timelineevent"."action_on" DESC, "timeline_timelineevent". >> "id" DESC> >> In [21]: len(Timeline.objects.raw(str(TimelineEvent.objects.filter(id__gt >> =100).query))) >> Out[21]: 89827 >> In [23]: str(TimelineEvent.objects.filter(id__gt=100, created_on__gt= >> datetime(2020, 1,1)).query) >> Out[23]: 'SELECT "timeline_timelineevent"."id", >> "timeline_timelineevent"."created_on", >> "timeline_timelineevent"."modified_on", >> "timeline_timelineevent"."action_on", >> "timeline_timelineevent"."timeline_id", >> "timeline_timelineevent"."content_type_id", >> "timeline_timelineevent"."object_id", "timeline_timelineevent"."action", >> "timeline_timelineevent"."meta" FROM "timeline_timelineevent" WHERE >> ("timeline_timelineevent"."created_on" > 2020-01-01 00:00:00+00:00 AND >> "timeline_timelineevent"."id" > 100) ORDER BY >> "timeline_timelineevent"."action_on" DESC, "timeline_timelineevent"."id" >> DESC' >> In [24]: len(Timeline.objects.raw(str(TimelineEvent.objects.filter(id__gt >> =100, created_on__gt=datetime(2020, 1, 1)).query))) >> ------------------------------------------------------------------------- >> -- >> ProgrammingError Traceback (most recent call last) >> /usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py in >> _execute(self, sql, params, *ignored_wrapper_args) >> 83 else: >> ---> 84 return self.cursor.execute(sql, params) >> 85 >> ProgrammingError: syntax error at or near "00" >> LINE 1: ...timeline_timelineevent"."created_on" > 2020-01-01 >> 00:00:00+0... >> ^ >> >> And this function is recommended on stackoverflow all other the place. >> >> What would change if instead of >> >> def __str__(self): >> sql, params = self.sql_with_params() >> return sql % params >> >> We will have >> >> def __str__(self): >> return '{} | {}'.format(sql, params) >> >> In that case nobody will ever want to use it as argument for raw function. >> >> Thank you. And please, let me know what you think about it >> >> -- >> 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/44595903-f679-4d08-abb8-80d2c8dec6e9n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-developers/44595903-f679-4d08-abb8-80d2c8dec6e9n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Adam > -- 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-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/0b098cc9-de56-4f4c-ad75-58713d7bdf46n%40googlegroups.com.