diff --git a/python/samba/netcmd/domain/models/fields.py b/python/samba/netcmd/domain/models/fields.py index a718de28348..0b7e1eb83e4 100644 --- a/python/samba/netcmd/domain/models/fields.py +++ b/python/samba/netcmd/domain/models/fields.py @@ -45,17 +45,20 @@ class Field(metaclass=ABCMeta): but really any field can be a list or single value. """ - def __init__(self, name, many=False, default=None, hidden=False): + def __init__(self, name, many=False, default=None, hidden=False, + readonly=False): """Creates a new field, should be subclassed. :param name: Ldb field name. :param many: If true always convert field to a list when loaded. :param default: Default value or callback method (obj is first argument) :param hidden: If this is True, exclude the field when calling as_dict() + :param readonly: If true don't write this value when calling save. """ self.name = name self.many = many self.hidden = hidden + self.readonly = readonly # This ensures that fields with many=True are always lists. # If this is inconsistent anywhere, it isn't so great to use. diff --git a/python/samba/netcmd/domain/models/model.py b/python/samba/netcmd/domain/models/model.py index 3f2fcbe8dda..602c6ca1248 100644 --- a/python/samba/netcmd/domain/models/model.py +++ b/python/samba/netcmd/domain/models/model.py @@ -336,7 +336,7 @@ class Model(metaclass=ModelMeta): message = Message(dn=self.dn) for attr, field in self.fields.items(): - if attr != "dn": + if attr != "dn" and not field.readonly: value = getattr(self, attr) try: db_value = field.to_db_value(ldb, value, FLAG_MOD_ADD) @@ -361,7 +361,7 @@ class Model(metaclass=ModelMeta): # Any fields that are set to None or an empty list get unset. message = Message(dn=self.dn) for attr, field in self.fields.items(): - if attr != "dn": + if attr != "dn" and not field.readonly: value = getattr(self, attr) old_value = getattr(existing_obj, attr)