Opened 9 years ago

Last modified 4 years ago

#26061 closed Bug

Queryset raises EmptyResultSet (instead of print SQL query) — at Initial Version

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

In [19]: import django

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.

Change History (0)

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