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

Entry in INSTALLED_APPS but not in SHARED_APPS or TENANT_APPS can't migrate #443

Open
goodtune opened this issue Feb 23, 2017 · 11 comments · May be fixed by #545
Open

Entry in INSTALLED_APPS but not in SHARED_APPS or TENANT_APPS can't migrate #443

goodtune opened this issue Feb 23, 2017 · 11 comments · May be fixed by #545
Assignees
Labels

Comments

@goodtune
Copy link
Collaborator

This bit me this morning... I added an application to INSTALLED_APPS but forgot to include it in TENANT_APPS; when I started migrating the migration code was not being executed, although the migration was being marked as processed, and even recorded in the database.

Ultimately though this is an error state - an application that isn't allocated one way or the other can't be migrated because we don't know if it is intended to be in SHARED_APPS or TENANT_APPS. Guessing or defaulting is worse, so I think the best solution is to add this to the system checks.

@goodtune goodtune added the bug label Feb 23, 2017
@goodtune goodtune self-assigned this Feb 23, 2017
@goodtune goodtune mentioned this issue Feb 24, 2017
@stephane
Copy link
Contributor

The installation could recommend to use:

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

Extracted from http://mycodesmells.com/post/django-tutorial-multi-tenant-setup

@bernardopires
Copy link
Owner

That's interesting, I was about to say the docs already recommend something similar and was surprised to see it doesn't. I completely agree it should @stephane. Please send a pull request for this. Thanks!

@amitjindal
Copy link

Hi, I am seeing another problem that is a little similar to this.
Please note that my project is a cookiecutter-django so the application directory structure is different.

Error

?: (tenant_schemas.E002) You have TENANT_APPS that are not in INSTALLED_APPS
	HINT: ['myapplication.reporter', 'myapplication.reviewer', 'raven.contrib.django.raven_compat']
?: (tenant_schemas.E003) You have SHARED_APPS that are not in INSTALLED_APPS
	HINT: ['myapplication.tenant_accounts']

System check identified 2 issues (0 silenced).

Here's my inclusion:

INSTALLED_APPS = DJANGO_SHARED_APPS + DJANGO_TENANT_APPS
SHARED_APPS = DJANGO_SHARED_APPS
TENANT_APPS = DJANGO_TENANT_APPS

Note that I did a print of these lists in the config and they seem perfectly fine to me:

INSTALLED_APPS
Broken into multiple lines for clarity below:

['tenant_schemas', 'myapplication.tenant_accounts', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 
'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'crispy_forms',
'allauth', 'allauth.account', 'allauth.socialaccount', 'attachments',
'organizations', 'django_ajax', 'myapplication.users',
'myapplication.core', 'myapplication.reporter', 'myapplication.reviewer',
'compressor', 'raven.contrib.django.raven_compat', 'gunicorn',
'storages', 'anymail']

SHARED_APPS

['tenant_schemas', 'myapplication.tenant_accounts']

TENANT_APPS

['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'crispy_forms', 'allauth',
'allauth.account', 'allauth.socialaccount', 'attachments', 'organizations',
'django_ajax', 'myapplication.users',
'myapplication.core', 'myapplication.reporter', 'myapplication.reviewer',
'compressor', 'raven.contrib.django.raven_compat', 'gunicorn',
'storages', 'anymail']

What I am seeing is:

  1. If I give name of the config instead of just the application, I get error that application is not in installed apps: e.g.:
LOCAL_APPS += ['myapplication.reviewer.apps.ReviewerConfig']
  1. If I don't give name of the config but just use default_app_config = 'myapplication.tenant_accounts.apps.TenantAccountsConfig' in __init__.py then also I get an error.
LOCAL_APPS += ['myapplication.reviewer']
default_app_config = 'myapplication.reviewer.apps.ReviewerConfig'
 -- or --
default_app_config = 'reviewer.apps.ReviewerConfig'
  1. When I don't give either, this works fine but other things like django shell manage.py shell is not able to load the models.
LOCAL_APPS += ['myapplication.reviewer']

Currently the application (Raven/Third party): 'raven.contrib.django.raven_compat' is still giving error.
There seems to be a bug with the code that does this system check as its not able to correctly identify the packages. Or perhaps I have missed a setting that sets this up correctly.

How do I work around this? Please help.

@amitjindal
Copy link

Here's a little more info that I see:

In my config I wrote similar code as: https://github.com/bernardopires/django-tenant-schemas/blob/master/tenant_schemas/apps.py#L82

The check passes when its running in config, but fails later. Not sure why.

Settings

print('--------------------------------------------------------------------------------------------')
INSTALLED_APPS = DJANGO_SHARED_APPS + DJANGO_TENANT_APPS
SHARED_APPS = set(DJANGO_SHARED_APPS)
TENANT_APPS = set(DJANGO_TENANT_APPS)

if not set(TENANT_APPS).issubset(INSTALLED_APPS):
    delta = set(TENANT_APPS).difference(INSTALLED_APPS)
    print("AMIT: You have TENANT_APPS that are not in INSTALLED_APPS: %s" % [a for a in TENANT_APPS if a in delta])
else:
    print("AMIT: TENANT_APPS check passed")

if not set(SHARED_APPS).issubset(INSTALLED_APPS):
    delta = set(SHARED_APPS).difference(INSTALLED_APPS)
    print("AMIT: You have SHARED_APPS that are not in INSTALLED_APPS: %s" % [a for a in SHARED_APPS if a in delta])
else:
    print("AMIT: SHARED_APPS check passed")
print('--------------------------------------------------------------------------------------------')

Output (Relevant Output)

System check identified 1 issue (0 silenced).
--------------------------------------------------------------------------------------------
AMIT: TENANT_APPS check passed
AMIT: SHARED_APPS check passed
--------------------------------------------------------------------------------------------
[2017-11-23 12:01:01,130] [  DEBUG] [base] [7122:140184782518016] - Configuring Raven for host: <raven.conf.remote.RemoteConfig object at 0x7f7f45e7c4e0>
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f7f45e1c598>
[2017-11-23 12:01:02,608] [  DEBUG] [base] [7122:140184609859328] - Sending message of length 1902 to https://sentry.io/api/234044/store/
Traceback (most recent call last):
  File "/webapps/myapplication/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/webapps/myapplication/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/webapps/myapplication/lib/python3.6/site-packages/django/core/management/base.py", line 405, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
?: (tenant_schemas.E002) You have TENANT_APPS that are not in INSTALLED_APPS
	HINT: ['raven.contrib.django.raven_compat']

System check identified 1 issue (0 silenced).

Any reason why this would be?

Thanks
Amit

@ivissani
Copy link

I'm experiencing the same problem as @amitjindal . As far as I can see the problem is located in the apps.py file and is a consequence of this piece of code

    # Take the app_configs and turn them into *old style* application names.
    # This is what we expect in the SHARED_APPS and TENANT_APPS settings.
    INSTALLED_APPS = [
        config.name
        for config in app_configs
    ]

The problem is that config.name for raven.contrib.django.raven_compat returns 'raven.contrib.django' therefore the following test

    if not set(settings.SHARED_APPS).issubset(INSTALLED_APPS):
        delta = set(settings.SHARED_APPS).difference(INSTALLED_APPS)
        errors.append(
            Error("You have SHARED_APPS that are not in INSTALLED_APPS",
                  hint=[a for a in settings.SHARED_APPS if a in delta],
                  id="tenant_schemas.E003"))

fails, producing the mentioned error.

Shouldn't this code:

    # Take the app_configs and turn them into *old style* application names.
    # This is what we expect in the SHARED_APPS and TENANT_APPS settings.
    INSTALLED_APPS = [
        config.name
        for config in app_configs
    ]

be erased and use settings.INSTALLED_APPS instead?

@cmabastar
Copy link

Hi,

Any resolution for this issue? I Just upgraded my package to 1.9.0 and now receiving this error for the sentry package.

@kranirudha
Copy link

Same here. Any resolution ?

@pmontepagano pmontepagano linked a pull request May 15, 2018 that will close this issue
@axelvdw
Copy link

axelvdw commented Sep 4, 2018

Any resolution for this issue? Having the same problem regarding the raven/sentry package.

@tobiasgoecke
Copy link

Same here. Any resolution ?

@cmabastar
Copy link

What i did was just rename the module.

# 'raven.contrib.django.raven_compat', latest django-tenant-schemas breaks this module
'raven.contrib.django',

@jlquichimbo
Copy link

jlquichimbo commented Jul 19, 2019

I just put a single name app in TENANT_APPS:

TENANT_APPS = ( 'app', 'usuarios', 'productos', 'ventas', 'medidas', # 'app.apps.AppConfig', # 'usuarios.apps.UsuariosConfig', # 'productos.apps.ProductosConfig', # 'ventas.apps.VentasConfig', # 'medidas.apps.MedidasConfig', )

And it works for me.

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

Successfully merging a pull request may close this issue.

10 participants