Code

Opened 2 years ago

Closed 2 years ago

#17146 closed Cleanup/optimization (invalid)

Django docs possiable error

Reported by: from_a_far@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords: documentation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

go to: https://docs.djangoproject.com/en/1.3/topics/db/queries/#complex-lookups-with-q-objects

and scroll down to:

Poll.objects.get(
    Q(question__startswith='Who'),
    Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
)

and it says it yealds the following SQL:

SELECT * from polls WHERE question LIKE 'Who%'
    AND (pub_date = '2005-05-02' OR pub_date = '2005-05-06')

Thats not true though is it? If it's Poll.objects.get(... it's only going to get one object isn't it?

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

It says 'roughly' translates, and it is correct. get() may or may not add a LIMIT clause (that's an implementation detail) - in fact it currently doesn't do any LIMIT clause, in order to be able to throw an exception when more than one object is matched.

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.