Opened 9 years ago

Closed 4 years ago

#26061 closed Bug (duplicate)

Empty queryset raises EmptyResultSet (instead of print SQL query)

Reported by: Adam Dobrawy Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords: EmptyResultSet
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by tsyplakou)

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

Change History (5)

comment:1 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #22973

comment:2 by tsyplakou, 4 years ago

This bug isn't duplicate - current bug still exists on Django 3.1.7 .

comment:3 by tsyplakou, 4 years ago

Resolution: duplicate
Status: closednew

comment:4 by tsyplakou, 4 years ago

Description: modified (diff)
Summary: Queryset raises EmptyResultSet (instead of print SQL query)Empty queryset raises EmptyResultSet (instead of print SQL query)
Version: 1.83.1

comment:5 by Tim Graham, 4 years ago

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top