-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add Django 1.7 support. #15
Conversation
6637ee8
to
98faa32
Compare
So far, its migrating and creates the schema properly when create a new Tenant. Regarding ModelForm and Create, Update, Detailview, where I need to specify the model that will use...do you have any suggestion or example of how to make it the cleanest way? Thank you so much in advance |
@arescope, I suggest you take a look at You should be able to define a normal |
hi @charettes . Yes I tried that and it is working properly. Thank you. So far, it is working, but I need to test much more, I've around 100 models to test. I will let you know during this days. |
@charettes actually I discover a bug...or something like that... When I created an initial migration it happens this # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='Notice',
fields=[
],
options={
'ordering': ['-pub_date'],
'managed': False,
},
bases=(models.Model,),
),
] is it normal??? |
bc4847e
to
e390387
Compare
e390387
to
85ac2f2
Compare
@arescope let me know if this works for you. I'll move the migration issue to another ticket. |
Hi @charettes, I got this error when running runserver Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/arescope/Projects/bwcored/appointments/models.py", line 28, in <module>
class Role(TimeStampedModel):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 204, in __new__
any(issubclass(base, TenantSpecificModel) for base in bases)):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 204, in <genexpr>
any(issubclass(base, TenantSpecificModel) for base in bases)):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/abc.py", line 161, in __subclasscheck__
ok = cls.__subclasshook__(subclass)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 182, in __subclasshook__
tenant_model = get_tenant_model(False)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/__init__.py", line 11, in get_tenant_model
from .settings import TENANT_MODEL
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/settings.py", line 54, in <module>
lazy_class_prepared(app_label, model_name, is_tenant_user_model)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/signals.py", line 15, in lazy_class_prepared
seed_cache=False, only_installed=False
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/utils.py", line 30, in get_model
return apps.get_model(app_label, model_name)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. |
The problem is with my CustomUserModel that it seems not loaded yet. Even in the INSTALLED_APPS is declared before. |
about the migrations, I did this and so far, is working. |
Hi, Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 109, in populate
app_config.import_models(all_models)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/config.py", line 201, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/arescope/Projects//bwcored/appointments/models.py", line 28, in <module>
class Role(TimeStampedModel):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 204, in __new__
any(issubclass(base, TenantSpecificModel) for base in bases)):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 204, in <genexpr>
any(issubclass(base, TenantSpecificModel) for base in bases)):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/abc.py", line 161, in __subclasscheck__
ok = cls.__subclasshook__(subclass)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 182, in __subclasshook__
tenant_model = get_tenant_model(False)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/__init__.py", line 21, in get_tenant_model
"been installed" % (app_label, object_name)
django.core.exceptions.ImproperlyConfigured: TENANCY_TENANT_MODEL refers to model 'estates.Estate' that has not been installed As far as i saw,ur method get_modelcalls apps.get_model. This method check if all the models have been loaded, that is not true at this point. As far as I understand the code, at the beginning apps.populate is called. That acquires apps._lock, so any time remove_from_app_cache is called it will try to acquire apps._lock, action which create a dead lock. So the solution is not using that lock, or use another way to clean the cache. Mostly this happen with multi-app projects I think. I hope all my input help you to fix the problem. |
0bdabb5 should deal with this. |
Hi, Having this now...assume that Role is Tenant Specific Model. Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/config.py", line 201, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/arescope/Projects//bwcored/appointments/models.py", line 28, in <module>
class Role(TimeStampedModel):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 292, in __new__
tenant_model = get_tenant_model(False)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/__init__.py", line 21, in get_tenant_model
"been installed" % (app_label, object_name)
django.core.exceptions.ImproperlyConfigured: TENANCY_TENANT_MODEL refers to model 'estates.Estate' that has not been installed |
Ok nailed it down in a2c75a8. |
Hi, that seems fixed. But still entering into the deadlock Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/apps/config.py", line 201, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/arescope/Projects//bwcored/cases/models.py", line 25, in <module>
class Case(TimeStampedModel):
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/models.py", line 273, in __new__
remove_from_app_cache(through)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/tenancy/utils.py", line 42, in remove_from_app_cache
raise Exception('Here it comes the deadlock')
Exception: Here it comes the deadlock This model has manytomany fields. and apps.populate(settings.INSTALLED_APPS) also acquires the lock. So maybe we should consider another way to clear the app_ache |
I see, the new I guess I'll need to prevent acquisition if the apps are not ready yet. |
e41f2df should do. |
Hi, There is no deadlock anymore! Thank you. However, I find a new issue, and is that the related_name in TenantMeta is not propagated to the tenant. That is because when call get_model, it is not ready the model still. I think for D1.7 changing from apps.get_model to apps.get_registered_model could be a solution. I tried by myself and it seems working. Thank you |
I'm not sure I understand what you mean.
|
Ahhh I think I understand what you mean! If the class has been prepared but has not been registered the related the descriptor will never be attached. Fixed in 1b879a6. |
Yup!! Thats it! Sorry for being so cryptic sometimes :). |
Oh, Still the issue I reported on #16 I applied this patch https://gist.github.com/arescope/3e422d14cd480fc8ca69 and seems to work |
Let's move the discussion on #16, I don't think the issue is related to Django 1.7 only. Unfortunately your patch completely removes the generic relation instead of making it work correctly. |
No description provided.