[Django] #29644: String representation of SearchQuery gives inaccurate results

9 views
Skip to first unread message

Django

unread,
Aug 6, 2018, 5:28:03 PM8/6/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Krupp |
Type: | Status: new
Uncategorized |
Component: | Version: 2.0
contrib.postgres |
Severity: Normal | Keywords: SearchQuery search
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
For the purpose of writing tests, I'm trying to use the string
representation of SearchQuery to see what query statements my querystring
parser is generating.

When I do {{{print(~SearchQuery('asdf'))}}}, instead of seeing
{{{"~SearchQuery('asdf')"}}} I instead see {{{"SearchQuery('asdf')"}}}. In
other words, the tilde that is used to negate the SearchQuery isn't being
shown.

Similarly, if I do:

{{{query = SearchQuery('a') & ( SearchQuery('b') | SearchQuery('c') )}}}

When I do {{{print(query)}}} I just see {{{"SearchQuery('a') &
SearchQuery('b') | SearchQuery('c')"}}}. The issue here is that the
parentheses used to group these statements aren't shown, which again
changes the meaning of this statement.

--
Ticket URL: <https://code.djangoproject.com/ticket/29644>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 6, 2018, 5:45:06 PM8/6/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
------------------------------------+------------------------------------
Reporter: Alex Krupp | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

It might be feasible to fix, I'm not sure.

--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:1>

Django

unread,
Aug 7, 2018, 5:33:08 PM8/7/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
------------------------------------+--------------------------------------
Reporter: Alex Krupp | Owner: Tom Forbes
Type: Bug | Status: assigned

Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Tom Forbes):

* owner: (none) => Tom Forbes
* status: new => assigned


Comment:

I've got a good fix for the negation, and a 'not sure if this a good idea'
fix for the grouping. PR: https://github.com/django/django/pull/10276

For the grouping we could fix it quite elegantly by always surrounding
`CombinedSearchQuery`'s in `()`, but this would mean the example above
would result in:

`(SearchQuery('a') & SearchQuery('b') | SearchQuery('c'))`

--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:2>

Django

unread,
Aug 7, 2018, 7:48:29 PM8/7/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
------------------------------------+--------------------------------------
Reporter: Alex Krupp | Owner: Tom Forbes
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Alex Krupp):

That seems like a good fix to me. I don't foresee much use for this
outside of writing tests. E.g. if you were going to log user searches so
that they were viewable in the admin or whatever, presumably you'd log
what the user typed rather than the parsed query.

--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:3>

Django

unread,
Aug 7, 2018, 7:59:04 PM8/7/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
------------------------------------+--------------------------------------
Reporter: Alex Krupp | Owner: Tom Forbes
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Tom Forbes):

Replying to [comment:3 Alex Krupp]:


> That seems like a good fix to me. I don't foresee much use for this
outside of writing tests. E.g. if you were going to log user searches so
that they were viewable in the admin or whatever, presumably you'd log

what the user typed rather than the parsed query. To the extent that you'd
want to log the parsed queries I think it would only be for compliance
purposes, but this would be fine for that since even with the parentheses
you can still re-run the query and get the same results just by copying
and pasting.

You might not be able to get the exact same results. One thing that's not
easy to fix (as far as I can see) are the quotation marks. So in my
example above it would more accurately be:

`(SearchQuery(a) & SearchQuery(b) | SearchQuery(c))`

I'm not sure if I like the extra parentheses around the query, it does
make it harder to read. But on the other hand it does make the
implementation simpler.

--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:4>

Django

unread,
Aug 9, 2018, 7:05:13 PM8/9/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
------------------------------------+--------------------------------------
Reporter: Alex Krupp | Owner: Tom Forbes
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Tom Forbes):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:5>

Django

unread,
Aug 10, 2018, 4:57:01 AM8/10/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
-------------------------------------+-------------------------------------
Reporter: Alex Krupp | Owner: Tom
| Forbes
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: SearchQuery search | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:6>

Django

unread,
Aug 15, 2018, 8:14:38 PM8/15/18
to django-...@googlegroups.com
#29644: String representation of SearchQuery gives inaccurate results
-------------------------------------+-------------------------------------
Reporter: Alex Krupp | Owner: Tom
| Forbes
Type: Bug | Status: closed
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: SearchQuery search | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a3df7574f934673d9c77154bb3e69917ebf85e3e" a3df757]:
{{{
#!CommitTicketReference repository=""
revision="a3df7574f934673d9c77154bb3e69917ebf85e3e"
Fixed #29644 -- Made SearchQuery.__str__() reflect negation and grouping.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:7>

Reply all
Reply to author
Forward
0 new messages