Django post_syncdb signal handler not getting a call?

I have myapp/management/__init__.pyone that registers a handler post_syncdbas follows:

from django.db.models import signals
from features import models as features

def create_features(app, created_models, verbosity, **kwargs):
    print "Creating features!"
    # Do stuff...

signals.post_syncdb.connect(create_features, sender=features)

I checked the following:

  • Both featuresand myapparesettings.INSTALLED_APPS
  • myapp.management loaded before syncdb starts (checked using print instructions at the module level)
  • The application is featuresprocessed syncdband it emits a signal post_syncdb(verified by checking the output syncdbwith --verbosity=2.
  • I use the same idiom for a different pair of applications, and this handler gets called correctly. I compared two modules and did not find significant differences between calls.

However, it is myapp.management.create_featuresnever called. What am I missing?

+3
3

models.py

+3

, , sender .

from django.db.models import signals
from features import models as features

def create_features(app, created_models, verbosity, **kwargs):
    print "Creating features!"
    if app != features #this will work as it compares models module instances
        return
    # Do stuff...

signals.post_syncdb.connect(create_features)

, , , Django. , , . , Signal django.dispatch.

+1

sender. , sender . sender db.models, , syncdb , .. . , .

, . , syncdb "foo.bar.myapp", foo.bar.myapp.models.

So, I decided to abandon the database and install the application again.

0
source

Source: https://habr.com/ru/post/1779254/


All Articles