From 61e156b3857c3877b1860b05e212409b94f4ace3 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Fri, 8 Mar 2019 11:14:10 -0500 Subject: [PATCH] Fix 'Models aren't loaded yet' warning on import categories.registration._process_registry was being called in categories/__init__.py, but since Django 1.9 it hasn't been possible to perform operations with models until the app registry is fully loaded. Currently the `AppRegistryNotReady` exception is being caught and printed, which means it is never actually executed on load. Since this code isn't currently doing anything (other than emitting a print() of a warning), I've removed it. --- categories/__init__.py | 13 ------------- categories/tests/test_mgmt_commands.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/categories/__init__.py b/categories/__init__.py index eae85e8..cc97aec 100644 --- a/categories/__init__.py +++ b/categories/__init__.py @@ -21,16 +21,3 @@ __version__ = get_version() default_app_config = 'categories.apps.CategoriesConfig' - - -def register(): - from categories import settings - from categories.registration import (_process_registry, registry) - _process_registry(settings.FK_REGISTRY, registry.register_fk) - _process_registry(settings.M2M_REGISTRY, registry.register_m2m) - - -try: - register() -except Exception as e: - print(e) diff --git a/categories/tests/test_mgmt_commands.py b/categories/tests/test_mgmt_commands.py index 78c1b28..96ba5a7 100644 --- a/categories/tests/test_mgmt_commands.py +++ b/categories/tests/test_mgmt_commands.py @@ -3,11 +3,22 @@ from unittest import skip from django.core import management from django.core.management.base import CommandError +from django.db import connection from django.test import TestCase class TestMgmtCommands(TestCase): + @classmethod + def setUpClass(cls): + connection.disable_constraint_checking() + super(TestMgmtCommands, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(TestMgmtCommands, cls).tearDownClass() + connection.enable_constraint_checking() + def test_add_category_fields(self): management.call_command('add_category_fields', verbosity=0)