Commit Graph

98 Commits

Author SHA1 Message Date
Andrew Godwin 9ae17d994b Make test stronger to hopefully fix odd Jenkins failure 2014-01-08 21:20:29 +00:00
Andrew Godwin 64887c644a Fixed #21142: Dependency failures on unmigrated apps. 2014-01-08 13:00:12 +00:00
Aymeric Augustin 7ed20e0153 Populated Apps instances immediately by default. 2013-12-30 22:11:17 +01:00
Aymeric Augustin 38ce41103f Used Apps.clear_cache() in tests that alter the app registry. 2013-12-29 21:25:28 +01:00
Aymeric Augustin 1716b7ce5a Renamed AppCache to Apps.
Also renamed app_cache to apps and "app cache" to "app registry".

Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
2013-12-24 12:25:17 +01:00
Aymeric Augustin 82a35e24d4 Replaced ad-hoc caching of get_models with lru_cache.
Invalidate properly the cache whenever all_models or app_configs change.
This fixes some isolation issues in the test suite.
2013-12-24 10:56:50 +01:00
Aymeric Augustin e32095616c Imported override_settings from its new location. 2013-12-23 21:37:56 +01:00
Aymeric Augustin da16bb30ff Dropped AppCache._empty, _with_app and _without_app.
It's now easier to achieve the same effect with modify_settings or
override_settings.
2013-12-23 21:37:56 +01:00
Aymeric Augustin 2fef9e5375 Moved apps back in the toplevel django namespace.
Reverted 4a56a93cc4.
2013-12-22 11:39:55 +01:00
Aymeric Augustin 2239081ff1 Expurged INSTALLED_APPS from code and tests.
Except the app cache code and a few specific tests, of course.
2013-12-22 11:39:18 +01:00
Aymeric Augustin f25fa9d859 Deprecated load_app().
Adjusted several tests that used it to add apps to the app cache and
then attempted to remove them by manipulating attributes directly.

Also renamed invalid_models to invalid_models_tests to avoid clashing
application labels between the outer and the inner invalid_models
applications.
2013-12-22 11:39:17 +01:00
Aymeric Augustin 742ed9878e Refactored registration of models.
Got rid of AppConfig._stub. As a side effect, app_cache.app_configs now
only contains entries for applications that are in INSTALLED_APPS, which
is a good thing and will allow dramatic simplifications (which I will
perform in the next commit). That required adjusting all methods that
iterate on app_configs without checking the "installed" flag, hence the
large changes in get_model[s].

Introduced AppCache.all_models to store models:
- while the app cache is being populated and a suitable app config
  object to register models isn't available yet;
- for applications that aren't in INSTALLED_APPS since they don't have
  an app config any longer.

Replaced get_model(seed_cache=False) by registered_model() which can be
kept simple and safe to call at any time, and removed the seed_cache
argument to get_model[s]. There's no replacement for that private API.

Allowed non-master app caches to go through populate() as it is now
safe to do so. They were introduced in 1.7 so backwards compatibility
isn't a concern as long as the migrations framework keeps working.
2013-12-22 11:39:17 +01:00
Aymeric Augustin 0242c56fd8 Deborgified the app cache.
Improved Andrew's hack to create temporary app caches to handle
migrations. Now the main app cache has a "master" flag set to True
(which is a non-default keyword argument, thus unlikely to be used by
mistake). Other app cache instances have "master" set to False.

The only sanctioned way to access the app cache is by importing
django.core.apps.app_cache.

If you were instanciating an app cache and relying on the Borg pattern,
you'll have to refactor your code.
2013-12-17 21:53:18 +01:00
Aymeric Augustin 6e895f9e06 Removed superfluous models.py files.
Added comments in the three empty models.py files that are still needed.

Adjusted the test runner to add applications corresponding to test
labels to INSTALLED_APPS even when they don't have a models module.
2013-12-17 11:16:48 +01:00
Aymeric Augustin 4a56a93cc4 Moved the new app cache inside core. 2013-12-17 10:17:46 +01:00
Aymeric Augustin ebda5800ae Simplified register_models.
Since it's never called with more than one model at a time the current
signature is needlessly complicated.
2013-12-17 10:17:45 +01:00
Aymeric Augustin b55282b98b Moved list of models inside AppConfig instances.
This commit is a refactoring with no change of functionality, according
to the following invariants:

- An app_label that was in app_configs and app_models stays in
  app_config and has its 'installed' attribute set to True.

- An app_label that was in app_models but not in app_configs is added to
  app_configs and has its 'installed' attribute set to True.

As a consequence, all the code that iterated on app_configs is modified
to check for the 'installed' attribute. Code that iterated on app_models
is rewritten in terms of app_configs.

Many tests that stored and restored the state of the app cache were
updated.

In the long term, we should reconsider the usefulness of allowing
importing models from non-installed applications. This doesn't sound
particularly useful, can be a trap in some circumstances, and causes
significant complexity in sensitive areas of Django.
2013-12-17 10:17:44 +01:00
Aymeric Augustin 8662654d6d Removed module-level functions for the app cache.
Since the original ones in django.db.models.loading were kept only for
backwards compatibility, there's no need to recreate them. However, many
internals of Django still relied on them.

They were also imported in django.db.models. They never appear in the
documentation, except a quick mention of get_models and get_app in the
1.2 release notes to document an edge case in GIS. I don't think that
makes them a public API.

This commit doesn't change the overall amount of global state but
clarifies that it's tied to the app_cache object instead of hiding it
behind half a dozen functions.
2013-12-17 10:17:44 +01:00
Aymeric Augustin 9217b89da3 Removed BaseAppCache.app_store.
It was only storing redundant information. This is part of the effort to
allow applications without a models module.
2013-12-17 10:17:44 +01:00
Aymeric Augustin 860c2c8bc5 Moved django.db.models.loading to django.apps.cache.
This commit doesn't contain any code changes; it's purely a refactoring.
2013-12-17 10:17:43 +01:00
Andrew Godwin 5db028affb Fix altering of SERIAL columns and InnoDB being picky about FK changes 2013-12-11 14:19:05 +00:00
Baptiste Mispelon 19e4374971 Fixed ModelState breaking when unique_together has unhashable elements. 2013-12-06 15:22:52 +01:00
Baptiste Mispelon aba75b0d71 Fixed TypeError when rendering ModelState with multiple bases. 2013-12-06 00:55:31 +01:00
Alex Gaynor cbf8e8aa12 Fixed a flake8 error 2013-12-05 08:08:34 -06:00
Andrew Godwin 3b8e46cbc7 Migration VCS conflict detection and --merge for makemigrations 2013-12-04 16:01:49 +00:00
Andrew Godwin ce05b8a69e Don't make a second migration if there was a force-null-default addcol. 2013-12-04 13:56:22 +00:00
Andrew Godwin 5e63977c0e Fixed #21438: makemigrations now detects ManyToManyFields 2013-11-27 15:28:33 +00:00
Alex Gaynor e5b7045422 flake8 fixes 2013-11-06 20:00:48 -08:00
Andrew Godwin 106b019dc9 Massive migration optimiser improvements + RenameModel opn 2013-11-06 13:47:58 +00:00
Alex Gaynor f67e18f39e Fixed all E251 violations 2013-11-03 10:17:58 -08:00
Tim Graham 36ded01527 Fixed #21302 -- Fixed unused imports and import *. 2013-11-02 15:24:56 -04:00
Alex Gaynor 8faaf03b86 Fixed some flake8 issues 2013-10-30 10:42:35 -07:00
Andrew Godwin e9cb333bc3 Auto-apply initial migrations if their tables exist already. 2013-10-30 15:17:49 +00:00
Ramiro Morales 88f03db05f Fixed test that reads a migration file from disk.
We need to make sure content read from the file is decoded from UTF-8
right from the start so Python doesn't try to use another encoding
(read: ASCII/CP1252 under Windows.)
2013-10-27 14:54:56 -03:00
Andrew Godwin 5ab8b5d72c Fix migration planner to fully understand squashed migrations. And test. 2013-10-23 22:56:54 +01:00
Alasdair Nicol c3aa2948c6 Fixed #21298 -- Fixed E301 pep8 warnings 2013-10-23 13:45:03 +01:00
Loic Bistuer e565e1332d Fixed #21275 -- Fixed a serializer error when generating migrations for contrib.auth.
The migration serializer now looks for a deconstruct method on any object.
2013-10-21 14:54:52 -04:00
Loic Bistuer 8d6953d55c Added support for serializing class methods. - Refs #21290.
The new handling allows us to do away with the whitelisting that was
required to support date and datetime objects.
2013-10-19 12:10:18 -04:00
Loic Bistuer 584110417f Fixed #21283 -- Added support for migrations if models is a package.
Thanks Markus Holtermann for the report.
2013-10-19 09:48:57 -04:00
Loic Bistuer 5008706345 Added test for a921f06 - refs #21280.
This commit also lays the groundwork for future tests for the
makemigrations command.
2013-10-17 12:08:17 -04:00
Andrew Godwin 42f8666f6a Improve migration optimizer to be able to optimize through other ops 2013-10-16 11:09:33 +01:00
Tim Graham 1dae4ac177 Whitespace cleanup.
* Removed trailing whitespace.
* Added newline to EOF if missing.
* Removed blank lines at EOF.
* Removed some stray tabs.
2013-10-10 16:49:20 -04:00
Javed Khan 4dbd95ad65 Fixed #21236 -- Allowed migrations to work with unique_together tuples.
Thanks hjwp for the report.
2013-10-07 09:39:14 -04:00
Andrew Godwin a80d9ab0fe Initial version of MigrationOptimizer and tests 2013-10-02 17:34:22 +01:00
Andrew Godwin f671fb9d11 Remove most errors when running migration tests twice 2013-09-25 16:11:05 +01:00
Andrew Godwin fe9f342d8c Allow callables as the argument to RunPython 2013-09-25 16:10:43 +01:00
Andrew Godwin 3b810c5656 Add RunPython migration operation and tests 2013-09-25 13:58:07 +01:00
Andrew Godwin 05656f2388 Add equality support for Project/ModelState 2013-09-25 13:47:46 +01:00
Markus Holtermann a772ea8117 Fixed #21115 -- Fixed NameError in migrate --list command 2013-09-17 12:53:59 -04:00
Markus Holtermann 5a424c2393 Fixed #21114 -- Migrations must not have a dependency to themselves. 2013-09-17 11:47:19 -04:00