diff --git a/osc/obs_api/xmlmodel/models.py b/osc/obs_api/xmlmodel/models.py index 77a5a08ec7..5633e8f92f 100644 --- a/osc/obs_api/xmlmodel/models.py +++ b/osc/obs_api/xmlmodel/models.py @@ -67,9 +67,7 @@ def to_bytes(self, validate=True): """ Return the object as XML in form of utf-8 encoded bytes. """ - if validate: - self._pre_save() - ET.indent(self._root, space=" ", level=0) + self._pre_save(validate=validate) return ET.tostring(self._root, encoding="utf-8", short_empty_elements=True) def to_string(self, validate=True): @@ -123,8 +121,9 @@ def validate(self, what=None): ex.xml = self.to_string(validate=False) raise - def _pre_save(self): - self.validate() + def _pre_save(self, validate=True): + if validate: + self.validate() self._sort_nodes() self._reindent(self._root) xml.indent(self._root)