summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRob van der Linde <rob@catalyst.net.nz>2023-06-19 13:23:33 +1200
committerAndrew Bartlett <abartlet@samba.org>2023-06-25 23:29:32 +0000
commitb00761da1d1777943f7ab4ef99dda0866f408053 (patch)
tree475129dfdb24c38f24d92996f3567947bdfe2481 /python
parentd7b04685680a05137867575e85723409be5e3693 (diff)
downloadsamba-b00761da1d1777943f7ab4ef99dda0866f408053.tar.gz
samba-b00761da1d1777943f7ab4ef99dda0866f408053.tar.bz2
samba-b00761da1d1777943f7ab4ef99dda0866f408053.zip
netcmd: domain: model stores ldb message for save
The message is stored in self._apply which also gets called by self.refresh() This is the better thing to do than fetching in save. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r--python/samba/netcmd/domain/models/model.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/python/samba/netcmd/domain/models/model.py b/python/samba/netcmd/domain/models/model.py
index b7a0a123c4f..f04176131b2 100644
--- a/python/samba/netcmd/domain/models/model.py
+++ b/python/samba/netcmd/domain/models/model.py
@@ -73,6 +73,10 @@ class Model(metaclass=ModelMeta):
:param kwargs: Optional input fields to populate object with
"""
+ # Used by the _apply method, holds the original ldb Message,
+ # which is used by save() to determine what fields changed.
+ self._message = None
+
for field_name, field in self.fields.items():
if field_name in kwargs:
default = kwargs[field_name]
@@ -155,6 +159,9 @@ class Model(metaclass=ModelMeta):
:param ldb: Ldb connection
:param message: Ldb Message object to apply
"""
+ # Store the ldb Message so that in save we can see what changed.
+ self._message = message
+
for attr, field in self.fields.items():
if field.name in message:
setattr(self, attr, field.from_db_value(ldb, message[field.name]))
@@ -340,9 +347,8 @@ class Model(metaclass=ModelMeta):
res = ldb.search(dn, scope=SCOPE_BASE)
self._apply(ldb, res[0])
else:
- # Fetch existing object to work out what fields changed.
- existing_msg = ldb.search(self.dn, scope=SCOPE_BASE)
- existing_obj = self.from_message(ldb, existing_msg[0])
+ # Existing Message was stored to work out what fields changed.
+ existing_obj = self.from_message(ldb, self._message)
# Only modify replace or modify fields that have changed.
# Any fields that are set to None or an empty list get unset.