bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 423 forks source link

app_configs is None error #414

Closed akama closed 7 years ago

akama commented 8 years ago

I'm using Django==1.9.11 & version 1.6.5 or 1.6.6 of django-tenant-schemas. I've just upgraded from django 1.7 and 1.5.2 of django-tenant-schemas if that clarifies issues. If I open a shell using ./manage.py shell then I get the following list of applications.

Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.apps import apps
>>> apps.get_app_configs()
[<AppConfig: customers>, <StaticFilesConfig: staticfiles>, <ContentTypesConfig: contenttypes>, <SitesConfig: sites>, <MessagesConfig: messages>, <AppConfig: CTF>, <AdminConfig: admin>, <AuthConfig: auth>, <AppConfig: storages>, <TenantSchemaConfig: tenant_schemas>, <SessionsConfig: sessions>]

Here is the exception that I get when starting the server.

Unhandled exception in thread started by <function wrapper at 0x10188bde8>
Traceback (most recent call last):
  File "/Users/user/.virtualenvs/application/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/user/.virtualenvs/application/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check(display_num_errors=True)
  File "/Users/user/.virtualenvs/application/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/user/.virtualenvs/application/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/user/Code/django-tenant-schemas/tenant_schemas/apps.py", line 22, in best_practice
    for config in app_configs
TypeError: 'NoneType' object is not iterable
mounirmesselmeni commented 8 years ago

I'm having the same issue with Django 1.10.3 From django doc, app_configs could be None:

The check function must accept an app_configs argument; this argument is the list of applications that should be inspected. If None, the check must be run on all installed apps in the project. The **kwargs argument is required for future expansion.

https://docs.djangoproject.com/en/1.10/topics/checks/#writing-your-own-checks

3811 commented 7 years ago

I am having the same issue, Django 1.10.4 and django-tenant-schemas 1.6.6

mounirmesselmeni commented 7 years ago

I had to monkey patch the Django check framework to be able to ignore this issue. You can use this as a temporary workaround.


# Patching django check due to https://github.com/bernardopires/django-tenant-schemas/issues/414
def patch_check_framework():
    from django.core.checks import registry

    def get_checks(self, include_deployment_checks=False):
        checks = [x for x in self.registered_checks if x.__module__ != 'tenant_schemas.apps']
        if include_deployment_checks:
            checks.extend(self.deployment_checks)
        return checks

    registry.CheckRegistry.get_checks = get_checks

patch_check_framework()```
goodtune commented 7 years ago

No pull requests yet, feel free to fix the problem and add the test.

goodtune commented 7 years ago

If you want to try d48f6f8 please let me know if it fixes the issue. I only have a phone at my disposal presently, unable to test and had to creat the branch vis the web UI.

mounirmesselmeni commented 7 years ago

@goodtune I still did not tried your fix but it looks good and the right behavior. I will let you know as soon as I try it and thanks for your effort.

goodtune commented 7 years ago

Merged d091d2e and tagged as v1.6.7 - still not pushing to PyPI.