Skip to content

Commit

Permalink
[4.4.x] Fix #647, fix #909 - Always parse delete object non-strict (b…
Browse files Browse the repository at this point in the history
…ackport #912) (#913)

When an object is deleted, the submitted object's values are
ignored except for the primary key. Therefore, there's no
need to validate them in strict mode.
This also disables the rules validator for deletion objects, re #909

(cherry picked from commit 3239354)
  • Loading branch information
mergify[bot] authored Feb 26, 2024
1 parent d27ae66 commit 5a2d6c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
31 changes: 17 additions & 14 deletions irrd/updates/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ def __init__(
self.rules_validator = RulesValidator(database_handler)
self.request_meta = request_meta

if delete_reason:
self.request_type = UpdateRequestType.DELETE

try:
self.rpsl_obj_new = rpsl_object_from_text(rpsl_text_submitted, strict_validation=True)
if self.request_type == UpdateRequestType.DELETE:
self.rpsl_obj_new = rpsl_object_from_text(rpsl_text_submitted, strict_validation=False)
if self.rpsl_obj_new.messages.errors():
self.status = UpdateRequestStatus.ERROR_PARSING
self.error_messages = self.rpsl_obj_new.messages.errors()
Expand All @@ -110,17 +115,15 @@ def __init__(

self._retrieve_existing_version()

if delete_reason:
self.request_type = UpdateRequestType.DELETE
if not self.rpsl_obj_current:
self.status = UpdateRequestStatus.ERROR_PARSING
self.error_messages.append(
"Can not delete object: no object found for this key in this database."
)
logger.debug(
f"{id(self)}: Request attempts to delete object {self.rpsl_obj_new}, "
"but no existing object found."
)
if self.request_type == UpdateRequestType.DELETE and not self.rpsl_obj_current:
self.status = UpdateRequestStatus.ERROR_PARSING
self.error_messages.append(
"Can not delete object: no object found for this key in this database."
)
logger.debug(
f"{id(self)}: Request attempts to delete object {self.rpsl_obj_new}, "
"but no existing object found."
)

def _retrieve_existing_version(self):
"""
Expand All @@ -132,12 +135,12 @@ def _retrieve_existing_version(self):
results = list(self.database_handler.execute_query(query))

if not results:
self.request_type = UpdateRequestType.CREATE
self.request_type = UpdateRequestType.CREATE if not self.request_type else self.request_type
logger.debug(
f"{id(self)}: Did not find existing version for object {self.rpsl_obj_new}, request is CREATE"
)
elif len(results) == 1:
self.request_type = UpdateRequestType.MODIFY
self.request_type = UpdateRequestType.MODIFY if not self.request_type else self.request_type
self.rpsl_obj_current = rpsl_object_from_text(results[0]["object_text"], strict_validation=False)
logger.debug(
f"{id(self)}: Retrieved existing version for object "
Expand Down Expand Up @@ -297,7 +300,7 @@ def validate(self) -> bool:
self.error_messages += self.rpsl_obj_new.messages.errors()
self.status = UpdateRequestStatus.ERROR_PARSING
return False
if self.rpsl_obj_new and self.request_type:
if self.rpsl_obj_new and self.request_type and self.request_type != UpdateRequestType.DELETE:
rules_result = self.rules_validator.validate(self.rpsl_obj_new, self.request_type)
self.info_messages += rules_result.info_messages
self.error_messages += rules_result.error_messages
Expand Down
7 changes: 1 addition & 6 deletions irrd/updates/tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ def test_parse_invalid_object_delete_syntax(self, prepare_mocks):
{"name": "person", "value": "Placeholder Person Object"},
{"name": "nic-hdl", "value": "PERSON-TEST"},
{"name": "changed", "value": "changed@example.com 20190701 # comment"},
{"name": "source", "value": "TEST"},
]
},
],
Expand Down Expand Up @@ -1110,12 +1109,8 @@ def test_parse_invalid_object_delete_syntax(self, prepare_mocks):
person: Placeholder Person Object
nic-hdl: PERSON-TEST
changed: changed@example.com 20190701 # comment
source: TEST
ERROR: Mandatory attribute "address" on object person is missing
ERROR: Mandatory attribute "phone" on object person is missing
ERROR: Mandatory attribute "e-mail" on object person is missing
ERROR: Mandatory attribute "mnt-by" on object person is missing
ERROR: Primary key attribute "source" on object person is missing
ERROR: Can not delete object: no object found for this key in this database.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 5a2d6c8

Please sign in to comment.