Opened 10 years ago
Last modified 10 years ago
#23305 closed Cleanup/optimization
Models that are imported on app's import time are invisible to makemigrations when the application is relabeld — at Version 9
Reported by: | Rafał Pitoń | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.7-rc-2 |
Severity: | Normal | Keywords: | afraid-to-commit |
Cc: | cmawebsite@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Models that are imported in app's __init__.py
, or by modules imported from that become invisible for Django if app uses apps.py and AppConfig.
To reproduce it create app with basic config and simple model in models.py. If this model is imported inside __init__.py
, or other module imported in __init__.py
, it will become invisible to makemigrations.
Tried this both with default_app_config as well as giving full path to AppConfig in INSTALLED_APPS.
I'm running latest code from 1.7 branch.
EDIT by (c-schmitt): This Bug Report only works when you import an Model in __init__.py
and relabel your application in AppConfig.
I Appended a Test and the user that submitted the bug also has an example application on github.
Change History (10)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Component: | Uncategorized → Migrations |
---|---|
Description: | modified (diff) |
Severity: | Normal → Release blocker |
Summary: | Models that are imported on app's import time are invisible to makemessages → Models that are imported on app's import time are invisible to makemigrations |
comment:3 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I cannot replicate this; I've tried importing the models in init.py directly, and via a submodule, with and without preexisting migrations directories, and all variants work perfectly. On master, this does raise the deprecation warning:
/home/andrew/Programs/DjangoTest/app_a/models.py:4: RemovedInDjango19Warning: Model class app_a.models.ModelTest doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class ModelTest(models.Model):
but it still works.
I'm closing as INVALID, but if you can supply me with either exact steps to follow or an example project and console commands to follow, and that causes the bug, we can reopen.
comment:4 by , 10 years ago
I've tried the same (just a little bit slower) and I've ran it against 1.7 and every test worked fine. Even when I imported the Model in apps.py.
I've created some unittests for that but It always worked as expected.
Also you should consider reading this: https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.ready
comment:5 by , 10 years ago
After creating custom project from scratch I can say that this indeed works. However I've created test case closer to what I'm experiencing and I've that it all boils down to presence to custom label attribute in AppConfig. As soon as that attribute is set to anything but default, model vanishes from makemigrations sight.
Here's source:
https://github.com/rafalp/Django-23305
Output looks like this:
> python manage.py makemigrations custom_admin No changes detected in app 'custom_admin'
So I'm in doubt now. Am I using labels wrong, or there's bug somewhere?
Either way thanks for attention and time!
comment:6 by , 10 years ago
Okai it seems that this bug is valid and only applies when you set a label on AppConfig and import a model in __init__.py
I also append some unit tests that could be used
The diff could be applied to stable/1.7.x
Also I'm reopening it and add additional details
by , 10 years ago
Attachment: | ticket_23305.diff added |
---|
comment:7 by , 10 years ago
Resolution: | invalid |
---|---|
Status: | closed → new |
comment:8 by , 10 years ago
Description: | modified (diff) |
---|---|
Summary: | Models that are imported on app's import time are invisible to makemigrations → Models that are imported on app's import time are invisible to makemigrations when the application is relabeld |
comment:9 by , 10 years ago
Description: | modified (diff) |
---|
I've fixed your Headline and marked it as a release blocker (since I think this bug should not be in 1.7, but maybe a core could change it to the correct status.)