Django database strange behavior - dev server is loading about minutes

viwal

please, I sent last days fighting with db and django.

My problem is: I have database 500 Mb big ... In db there are not any many_to_many, foreing etc. so tables are not independent one to another. In django I have created model by using inspectdb. My problem is that once I call runserver I have to wait about 5 minutes before server starts. I have tried debug by use python -vv manage.py runserver to seee where the server get stuck, and it's always when try connect to the database.

I have tried same db structure with MySQL, PostgreSQL, MSSQL but all databases behaves same. Also on different machines and different django versions.

Once I created db dump without datas, only db structure so size of db wat about 16Kb and than Django server starts fast(miliseconds).

I use django version 1.9.5 but have tried also 1.8

Please every tip will be appreciated, actually I am at the end of my ideas where to search for the problem.

Thanks

viwal

So, after few days debugging and asking on IRC, I have a reason why the runserver (and almost every manage.py command) takes that long time. Django seems does not check SQL queries in views.py where I have most of my SQL queries. But I have two easy queries in my forms.py, to fill dropdown in my form and that cause whole problem.

So now I know where problem is, but I am thinking how to resolve it. Thing is that I need data from my models in my form.

My form looks:

def get_vendor_set():
    """
    Returns set of contributors to use as choices
    """
    vendor_set = [  
        ('Availability', 'Availability'),
        ('No Competitor', 'No Competitor'),         
        ('Popularity', 'Popularity'),
    ]
    contrib = CompetitorLastPrice.objects.order_by('vendor')
    for con in contrib:
        vendor_set.append((con.vendor,con.vendor))

    return sorted(set(vendor_set))


def get_sorg_set():
    """
    Return set of sorg to use as choices
    """
    sorg_set = []
    sorg_cursor = CltSorg.objects.all()
    for sorg in sorg_cursor:
        sorg_set.append((sorg.sorg, sorg.sorg +' - '+ sorg.sorg_description))

    return sorg_set


class FamilyForm(forms.ModelForm):

    class Meta:
        model = Family
        fields = ['name', 'family_number', 'price_list', 'sorg', 'filter', 'linearity']
        widgets = { 
            'sorg': forms.Select(choices=get_sorg_set()),
        }


class CustomInlineFormset(BaseInlineFormSet):
    """
    Custom formset that support initial data
    """
    ...
    ...

ContribFormSet = inlineformset_factory(Family, Templates, formset=CustomInlineFormset,
                                       fields='__all__', min_num=1, extra=0,
                                       widgets={'contributor' : forms.Select(choices=get_vendor_set())}
)

The problems causes those widgets... Is there any other way how to get data to the initial form (to the choice list) somewhere out of the forms.py ...I am thinking to do it in views.py somehow.

Thanks for any answer.

V.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

about generics strange behavior for me

Strange behavior in meteor app and database

NLog strange behavior on production server

Django Template strange behavior of layout

Strange behavior about WEXITSTATUS with `G++ 4.9.4`

Intellij evaluator strange behavior about string pool

A strange behavior about constructors in C++

go database/sql - strange connection and transaction behavior

Entity Framework database first on dll strange behavior

Strange behavior trying to connect SQLite database

Django https with a dev server

Strange behavior of SQL Server - random selection

Django 1.11 - strange behavior in get_or_create

loading admin page after upgrading to django 3.0 crashes dev. server

Strange behavior when loading assemblies and its dependencies programatically

Accidentally loading angularjs multiple times causes strange behavior

Can any one explain this strange behavior about Array sort?

Confused about strange import behavior within plpython stored procedures

About Database Settings in Django Project

strange query in server logs REMOTE HI_SRDK_DEV_GetHddInfo

Run node.js server with IIS: strange permission behavior

Strange behavior with SQL Server returning decimals with no decimal values

Using input time in Blazor server side has strange behavior

Strange NS behavior on OS X — can't connect to SSH server

Django strange behavior: manage.py commands do not end

Django's get_current_language strange behavior

Strange behavior in select drop-down in a Django template

Django with database on SQL Server

Error loading image filepath from the database in django