Skip to content

Commit 5f78c98

Browse files
committed
DNS: validate record's type with kind and sync them on update and insert
1 parent fd8775d commit 5f78c98

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

genesis_core/user_api/dns/dm/models.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,24 @@ class Record(CommonModel):
200200
def __init__(self, domain: Domain, **kwargs) -> None:
201201
super().__init__(domain=domain, domain_id=domain.id, **kwargs)
202202

203+
self._fill_n_validate_record()
204+
205+
def _fill_n_validate_record(self) -> None:
203206
if self.type != self.record.kind:
204207
raise ValueError("Types of model and record must match")
205208

206-
self._fill_from_record()
207-
208-
def _fill_from_record(self) -> None:
209209
self.content = self.record.get_content(self.domain)
210210
self.name = self.record.get_name(self.domain)
211211

212-
def save(self, session=None):
213-
self._fill_from_record()
212+
def update(self, session=None, force=False):
213+
self._fill_n_validate_record()
214+
215+
super().update(session=session, force=force)
214216

215-
super().save(session=session)
217+
def insert(self, session=None):
218+
self._fill_n_validate_record()
219+
220+
super().insert(session=session)
216221

217222
def delete(self, session=None, force=False, **kwargs):
218223
if not force and self.type == "SOA":

0 commit comments

Comments
 (0)