diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 7ace6f67c3..a214bfe3c7 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -1868,5 +1868,17 @@ from awx.main.access import * User.add_to_class('get_queryset', get_user_queryset) User.add_to_class('can_access', check_user_access) +# Monkeypatch Django serializer to ignore django-taggit fields (which break +# the dumpdata command; see https://github.com/alex/django-taggit/issues/155). +from django.core.serializers.python import Serializer as _PythonSerializer +_original_handle_m2m_field = _PythonSerializer.handle_m2m_field +def _new_handle_m2m_field(self, obj, field): + try: + field.rel.through._meta + except AttributeError: + return + return _original_handle_m2m_field(self, obj, field) +_PythonSerializer.handle_m2m_field = _new_handle_m2m_field + # Import signal handlers only after models have been defined. import awx.main.signals diff --git a/awx/main/tests/commands.py b/awx/main/tests/commands.py index 04636c3b62..5ebcbceaac 100644 --- a/awx/main/tests/commands.py +++ b/awx/main/tests/commands.py @@ -24,7 +24,8 @@ from awx.main.licenses import LicenseWriter from awx.main.models import * from awx.main.tests.base import BaseTest, BaseLiveServerTest -__all__ = ['CleanupDeletedTest', 'CleanupJobsTest', 'InventoryImportTest'] +__all__ = ['DumpDataTest', 'CleanupDeletedTest', 'CleanupJobsTest', + 'InventoryImportTest'] TEST_PLAYBOOK = '''- hosts: test-group gather_facts: False @@ -163,6 +164,20 @@ class BaseCommandMixin(object): result = CommandError(captured_stderr) return result, captured_stdout, captured_stderr +class DumpDataTest(BaseCommandMixin, BaseTest): + ''' + Test cases for dumpdata management command. + ''' + + def setUp(self): + super(DumpDataTest, self).setUp() + self.create_test_inventories() + + def test_dumpdata(self): + result, stdout, stderr = self.run_command('dumpdata') + self.assertEqual(result, None) + data = json.loads(stdout) + class CleanupDeletedTest(BaseCommandMixin, BaseTest): ''' Test cases for cleanup_deleted management command.