Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2271 closed defect (fixed)

__exact is only optional for top level queries

Reported by: russellm Owned by: russellm
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords: __exact query
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Django documentation states that:


If you don't provide a lookup type -- that is, if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be exact.

For example, the following two statements are equivalent:

Blog.objects.get(id=14)
Blog.objects.get(id__exact=14)

This is for convenience, because exact lookups are the common case.


While this is true for the provided example, it is not true for joined queries:

Blog.objects.get(author__id=14)
Blog.objects.get(author__id__exact=14)

The second query works - the first one fails because "id" is not a valid query term.

The fault appears to be in the code in parse_lookup that does pk 'faking' of queries - this code relies upon a query size of 1 to determin the assumed __exact, which fails if there are multiple query terms.

Attachments (0)

Change History (3)

comment:1 Changed 8 years ago by jacob

So should the query parser just append "exact" if the last word isn't a lookup type?

comment:2 Changed 8 years ago by russellm

Yes, that is what I am suggesting. There are some edge cases where this will fail with models that have query terms as field names, but these edge cases would continue to work as long as queries were fully expressed.

comment:3 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [3248]) Fixes #2271 -- Added code to imply __exact on any query argument that doesn't finish with a known query term.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.