Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26396 closed Bug (invalid)

ModelChoiceField shows only 100 choices with mysql.connector.django

Reported by: Piotr Kaczyński Owned by: nobody
Component: Forms Version: 1.8
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

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.

Change History (5)

comment:1 by Tim Graham, 9 years ago

Can you please give steps to reproduce this?

comment:2 by Piotr Kaczyński, 9 years ago

Sure. I checked more throughly and I found that it is a problem with mysql database. Here's my conf:

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': '***',
        'USER': 'energyportal',
        'PASSWORD': '****',
        'OPTIONS': {
          'autocommit': True,
        },
        'TEST': {
            'NAME': 'energyportal_test',
        },
    }
}

And here's test code:

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.

comment:3 by Tim Graham, 9 years ago

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.

comment:4 by Piotr Kaczyński, 9 years ago

Resolution: wontfix
Status: newclosed

Works fine with django.db.backends.mysql.

comment:5 by Tim Graham, 9 years ago

Resolution: wontfixinvalid
Summary: ModelChoiceField shows only 100 choicesModelChoiceField shows only 100 choices with mysql.connector.django
Note: See TracTickets for help on using tickets.
Back to Top