Code

Opened 2 years ago

Closed 2 years ago

#18066 closed Bug (needsinfo)

ModelChoiceIterator reports incorrect length

Reported by: BerislavLopac Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On line 899 of django/forms/models.py, the __len__ method returns the length of self.queryset, which always return as one -- instead, shouldn't it return the length of self.queryset.all()?

I have tried to get {% my_fk_field.choices|length %} and it kept returning as 1 -- only when I put {% my_fk_field.choices.queryset.all|length %} I got the correct length. I might be mistaken, but this looks like a bug to me...

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by claudep

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

I cannot reproduce the error, we will need some more code to see what's wrong here. Generally, calling len() on a queryset is a totally valid method to get the result length.

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.