From: Rob van der Linde Date: Sun, 24 Mar 2024 10:36:22 +0000 (+1300) Subject: python: domain: models: as_dict() should also exclude empty list fields X-Git-Tag: tdb-1.4.11~1347 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed07dee8649eaf4266965e959e3d4c0b7e1c8a3e;p=thirdparty%2Fsamba.git python: domain: models: as_dict() should also exclude empty list fields Empty list fields happen if many=True is used on the field. This means that the field is automatically initialised as an empty list, so this can only ever be sa list or None. The side-effect of this was that it appears in as_dict() when it shouldn't, because the field isn't populated. This fixes it. Signed-off-by: Rob van der Linde Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/domain/models/model.py b/python/samba/domain/models/model.py index 55cada972b6..56dacc9ddb4 100644 --- a/python/samba/domain/models/model.py +++ b/python/samba/domain/models/model.py @@ -193,7 +193,7 @@ class Model(metaclass=ModelMeta): for attr, field in self.fields.items(): if not field.hidden or include_hidden: value = getattr(self, attr) - if value is not None: + if value not in (None, []): obj_dict[field.name] = value return obj_dict