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.
* 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>
* 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>
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>
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>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:5>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29644#comment:6>
* 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>