From 7cc349e27836f760e2a14b65e690473bd63bf3ad Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 23 Sep 2015 20:25:49 +0200 Subject: Reporting: Replace _meta.get_all_field_names() for django 1.8 The _meta API was changed with django 1.8 and get_fields() now returns all model fields even fields defined in related models. But while creating the Entries we use this field list for construction and the list should only contain local fields. --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index 7acd9e293..ac0cde783 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -24,6 +24,16 @@ from Bcfg2.Reporting.models import * from Bcfg2.Reporting.Compat import transaction +def get_all_field_names(model): + if django.VERSION[0] == 1 and django.VERSION[1] >= 8: + return [field.name + for field in model._meta.get_fields() + if field.auto_created == False and + not (field.is_relation and field.related_model is None)] + else: + return model._meta.get_all_field_names() + + class DjangoORM(StorageBase): options = StorageBase.options + [ Bcfg2.Options.Common.repository, @@ -80,7 +90,7 @@ class DjangoORM(StorageBase): for attr in boolean + ["current_exists"]: xforms[attr] = boolean_xform act_dict = dict(state=state) - for fieldname in entrytype._meta.get_all_field_names(): + for fieldname in get_all_field_names(entrytype): if fieldname in ['id', 'hash_key', 'state']: continue try: -- cgit v1.2.3-1-g7c22