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-developers+unsubscr...@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.