Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal not called #603

Closed
maxthevoice opened this issue Jun 26, 2019 · 2 comments
Closed

Signal not called #603

maxthevoice opened this issue Jun 26, 2019 · 2 comments

Comments

@maxthevoice
Copy link

I have an issue since I installed the library. The signals are not called anymore. When creating a User, for example, a Profile instance should be created, but it doesn't.

signals.py:

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        models.Profile.objects.create(user=instance)

tests.py:

class TestCreateUserProfile(TenantTestCase):
    def test_create_user_profile(self):
        user = UserFactory()  # Factory boy
        self.assertIsInstance(user.profile, models.Profile)

settings.py:

SHARED_APPS = (
    'tenant_schemas',
    'dal',
    'dal_select2',

    'django.contrib.contenttypes',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.postgres',

    'allauth',
    'allauth.account',
    'corsheaders',
    'django_cleanup',
    'django_extensions',
    'debug_toolbar',
    'localized_fields',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'simple_history',
    'versatileimagefield',
    'timezone_field',
    'ordered_model',
    'django_filters',
    'phonenumber_field',
    'djcelery_email',
    'mjml',

    'core',
    'core_project',
    'two_factor_auth',
    'users',
    'controls',
    'occurrences',
    'organizations',
)

TENANT_APPS = (
    'django.contrib.contenttypes',

    'controls',
    'occurrences',
)

INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]

TENANT_MODEL = 'organizations.Organization'

DATABASES = {
    'default': {
        'ENGINE': 'psqlextra.backend',
        'NAME': env.str('POSTGRES_DB'),
        'USER': env.str('POSTGRES_USER'),
        'PASSWORD': env.str('POSTGRES_PASSWORD'),
        'HOST': env.str('POSTGRES_HOST', 'postgres'),
        'PORT': 5432,
    },
}

ORIGINAL_BACKEND = 'django.db.backends.postgresql'
POSTGRES_EXTRA_DB_BACKEND_BASE = 'tenant_schemas.postgresql_backend'

DATABASE_ROUTERS = (
    'tenant_schemas.routers.TenantSyncRouter',
)

I tried with tenant_schemas.postgresql_backend directly as the main ENGINE, but I got the same issue. So I don't think it's related with psqlextra.

I tried it directly from the admin, and I have the same issue.

Let me know if you need more details.

@maxthevoice
Copy link
Author

It's probably related to the fact that we need to use the name of the app instead of the relative path users.apps.UsersConfig.

I think #569 will fix this issue.

apps.py

class UsersConfig(AppConfig):
    name = 'users'

    def ready(self):
        import users.signals

The signals are not imported.

@maxthevoice
Copy link
Author

I used Django Tenants library instead. The import of apps is better and don't interfer with signals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant