[Django] #26396: ModelChoiceField shows only 100 choices

66 views
Skip to first unread message

Django

unread,
Mar 22, 2016, 9:51:20 AM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices
----------------------------+--------------------
Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
This somehow is connected to ModelChoiceIterator which returns proper
len() value, but making a list() gives a len() of 101.

I do not know the reason for that nor I have found any documentation about
it.

See Select.render_option for the field qith queryset longer than 100 rows.

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

Django

unread,
Mar 22, 2016, 10:11:43 AM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices
----------------------------+--------------------------------------

Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can you please give steps to reproduce this?

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

Django

unread,
Mar 22, 2016, 11:08:01 AM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices
----------------------------+--------------------------------------

Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by pkaczynski):

Sure. I checked more throughly and I found that it is a problem with mysql
database. Here's my conf:
{{{#!python
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '***',
'USER': 'energyportal',
'PASSWORD': '****',
'OPTIONS': {
'autocommit': True,
},
'TEST': {
'NAME': 'energyportal_test',
},
}
}
}}}

And here's test code:

{{{#!python
class DjangoTicket26396(TestCase):

def test_example(self):
from django.forms.models import ModelChoiceField
from django.forms.widgets import Select
from energycore.models.retail import Contract
from energycore.models import Client
client = Client.objects.create(
name='test',
short_name='test',
)
invoice_category = InvoiceCategory.objects.create(
symbol='TST', type='sell', description='test'
)
for i in range(1315):
Contract.objects.create(side=client, number='123',
payment_due_days=1,
invoice_category=invoice_category,
revise_invoice_category=invoice_category)
f = ModelChoiceField(queryset=Contract.objects.all(),
widget=Select)
self.assertEquals(len(f.choices), 1316)
self.assertEquals(len([e for e in f.choices]), 1316)
}}}

The only thing is that it doesn't work (i.e. test passses) for plain
models like "User" - I tried. However for my models it doesn't. It seems
like foreign key issue.

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

Django

unread,
Mar 22, 2016, 12:39:30 PM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices
----------------------------+--------------------------------------

Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by timgraham):

Can you reproduce with the `django.db.backends.mysql` backend? If not, I
guess the problem is in `mysql.connector.django` which is provided by
Oracle, not the Django team. If so, can you provide the models for your
test or (ideally) a test for Djanog's test suite? There are some tests for
`ModelChoiceField` in `model_forms/tests.py`.

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

Django

unread,
Mar 22, 2016, 1:10:47 PM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices
----------------------------+--------------------------------------
Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.8
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by pkaczynski):

* status: new => closed
* resolution: => wontfix


Comment:

Works fine with `django.db.backends.mysql`.

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

Django

unread,
Mar 22, 2016, 9:18:56 PM3/22/16
to django-...@googlegroups.com
#26396: ModelChoiceField shows only 100 choices with mysql.connector.django
----------------------------+--------------------------------------
Reporter: pkaczynski | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.8
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by timgraham):

* resolution: wontfix => invalid


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

Reply all
Reply to author
Forward
0 new messages