From f500167d2aae88d9b2a68fb792a9cad797a9338b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 21 Nov 2016 19:13:07 +0100 Subject: Reporting/Storage: Load django models after option parsing django get setup during option parsing and we cannot acces "django.db.models" before. So we need to delay the import of the models until the option parsing is ready. --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index 27040feb6..cdfab7704 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -20,13 +20,23 @@ from django.core.cache import cache #Used by GetCurrentEntry import difflib from Bcfg2.Compat import b64decode -from Bcfg2.Reporting.models import \ - Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ - Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ - FailureEntry, Performance, BaseEntry from Bcfg2.Reporting.Compat import transaction +def load_django_models(): + """ Load models for Django after option parsing has completed """ + # pylint: disable=W0602 + global Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ + Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ + FailureEntry, Performance, BaseEntry + # pylint: enable=W0602 + + from Bcfg2.Reporting.models import \ + Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ + Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ + FailureEntry, Performance, BaseEntry + + def get_all_field_names(model): if django.VERSION[0] == 1 and django.VERSION[1] >= 8: return [field.name @@ -45,6 +55,7 @@ class DjangoORM(StorageBase): type=Bcfg2.Options.Types.size, help='Reporting file size limit', default=1024 * 1024)] + options_parsed_hook = staticmethod(load_django_models) def _import_default(self, entry, state, entrytype=None, defaults=None, mapping=None, boolean=None, xforms=None): -- cgit v1.2.3-1-g7c22