Fixed #21283 -- Added support for migrations if models is a package. #1772

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Member

loic commented Oct 18, 2013

Refs #14300.

@MarkusH MarkusH and 1 other commented on an outdated diff Oct 18, 2013

django/db/models/loading.py
@@ -185,6 +185,16 @@ def get_apps(self):
return [elt[0] for elt in apps]
+ def _get_app_package(self, app):
+ if hasattr(app, '__path__'): # models/__init__.py package
+ app_package = '.'.join(app.__package__.split('.')[:-1])
+ else: # models.py module
+ app_package = app.__package__
+ return app_package
+
+ def get_app_package(self, app_label):
@loic

loic Oct 18, 2013

Member

As discussed on IRC, it's not strictly necessary but it's good to have a canonical way of doing this in Django. That way new features don't have to reinvent the wheel, and don't accidentally forget to handle model packages in the process.

@timgraham timgraham and 1 other commented on an outdated diff Oct 18, 2013

tests/migrations/models/__init__.py
@@ -0,0 +1,2 @@
+from .unicode import *
@timgraham

timgraham Oct 18, 2013

Owner

I'm trying to eradicate import * and use __all__ so we don't have unused imports (see #1770). Let me know if you have thoughts on the matter.

@loic

loic Oct 18, 2013

Member

Fixed it since * is not needed here.

@timgraham timgraham and 1 other commented on an outdated diff Oct 18, 2013

tests/migrations/models/__init__.py
@@ -0,0 +1,2 @@
+from .unicode import UnicodeModel
+from .unserializable import UnserializableModel
@timgraham

timgraham Oct 18, 2013

Owner

__all__ = (UnicodeModel, UnserializableModel) ?

@loic

loic Oct 18, 2013

Member

Indeed, I missed the point, the issue wasn't the * but the resulting unused import.

Owner

timgraham commented Oct 18, 2013

My mistake regarding my comment earlier about it working for me before your patch was applied, I didn't read the ticket carefully. This indeed works for me. With this change, are we now testing the code path where models is not a package though?

Member

loic commented Oct 18, 2013

@timgraham, the code path only differs on that else clause: https://github.com/loic/django/blob/ebcfecd371d9d7603f7353d00522faef414b6688/django/db/models/loading.py#L191.

If we want to test both code paths, it warrants an entirely new app, with it's own entry in ALWAYS_INSTALLED_APPS; dunno if it's necessary. Otherwise, I may be able to fake it, by testing only the output of MigrationWriter.path.

@loic loic Fixed #21283 -- Added support for migrations if models is a package.
Refs #14300.

Thanks Markus Holtermann for the report and the original attempt.
509ca76
Owner

timgraham commented Oct 19, 2013

merged in 5841104 - thanks!

timgraham closed this Oct 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment