In [20]: django.VERSION
Out[20]: (1, 8, 7, 'final', 0)
In [21]: print Record.objects.filter(pk__in=[])
[]
In [22]: print Record.objects.filter(pk__in=[]).query
---------------------------------------------------------------------------
EmptyResultSet Traceback (most recent call
last)
<ipython-input-22-e81ae73ee15f> in <module>()
----> 1 print Record.objects.filter(pk__in=[]).query
/home/adas/.virtualenvs/poradnia/local/lib/python2.7/site-
packages/django/db/models/sql/query.pyc in __str__(self)
213 done by the database interface at execution time.
214 """
--> 215 sql, params = self.sql_with_params()
216 return sql % params
217
/home/adas/.virtualenvs/poradnia/local/lib/python2.7/site-
packages/django/db/models/sql/query.pyc in sql_with_params(self)
221 substituted into the query.
222 """
--> 223 return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
224
225 def __deepcopy__(self, memo):
/home/adas/.virtualenvs/poradnia/local/lib/python2.7/site-
packages/django/db/models/sql/compiler.pyc in as_sql(self, with_limits,
with_col_aliases, subquery)
385 from_, f_params = self.get_from_clause()
386
--> 387 where, w_params = self.compile(self.query.where)
388 having, h_params = self.compile(self.query.having)
389 params = []
/home/adas/.virtualenvs/poradnia/local/lib/python2.7/site-
packages/django/db/models/sql/compiler.pyc in compile(self, node,
select_format)
355 sql, params = vendor_impl(self, self.connection)
356 else:
--> 357 sql, params = node.as_sql(self, self.connection)
358 if select_format and not self.subquery:
359 return node.output_field.select_format(self, sql,
params)
/home/adas/.virtualenvs/poradnia/local/lib/python2.7/site-
packages/django/db/models/sql/where.pyc in as_sql(self, compiler,
connection)
131 return '', []
132 else:
--> 133 raise EmptyResultSet
134 if full_needed - everything_childs <= 0:
135 if self.negated:
EmptyResultSet:
}}}
I expect to achieve SQL query not exception.
There is #10181, but it was about query execution. My issues is about
query printing.
--
Ticket URL: <https://code.djangoproject.com/ticket/26061>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0
Comment:
Duplicate of #22973
--
Ticket URL: <https://code.djangoproject.com/ticket/26061#comment:1>
Comment (by tsyplakou):
This bug isn't duplicate - current bug still exists on Django 3.1.7 .
--
Ticket URL: <https://code.djangoproject.com/ticket/26061#comment:2>
* status: closed => new
* resolution: duplicate =>
--
Ticket URL: <https://code.djangoproject.com/ticket/26061#comment:3>
* version: 1.8 => 3.1
Old description:
New description:
{{{
Internal Server Error: /api/travel/places/
Traceback (most recent call last):
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/User/Projects/travel/travel_backend/travel/views.py", line
2141, in export
sql, params = queryset.none().query.sql_with_params()
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/db/models/sql/query.py", line 264, in sql_with_params
return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/db/models/sql/compiler.py", line 513, in as_sql
where, w_params = self.compile(self.where) if self.where is not None
else ("", [])
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/db/models/sql/compiler.py", line 430, in compile
sql, params = node.as_sql(self, self.connection)
File "/Users/User/Projects/travel_envs/back_env/lib/python3.8/site-
packages/django/db/models/sql/where.py", line 99, in as_sql
raise EmptyResultSet
django.core.exceptions.EmptyResultSet
}}}
**AnyModel.objects.none().query.sql_with_params()** raises
**django.core.exceptions.EmptyResultSet**
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26061#comment:4>
* status: new => closed
* resolution: => duplicate
Comment:
This ticket reports the same issue as #22973, therefore it's a duplicate.
That ticket is closed as wontfix because the behavior is by design.
--
Ticket URL: <https://code.djangoproject.com/ticket/26061#comment:5>