-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix in modified action delete API #5351
Conversation
@@ -264,6 +264,9 @@ def delete(self, ref_or_id, requester_user): | |||
"Exception was %s", | |||
e, | |||
) | |||
action = ActionAPI.from_model(action_db) | |||
action_db = ActionAPI.to_model(action) | |||
Action.add_or_update(action_db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you modify the unit tests to cover this change?
@@ -264,6 +264,9 @@ def delete(self, ref_or_id, requester_user): | |||
"Exception was %s", | |||
e, | |||
) | |||
action = ActionAPI.from_model(action_db) | |||
action_db = ActionAPI.to_model(action) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to covert the models to ActionAPI and back to ActionDB here?
@m4dcoder I have polished code and added new unit test to cover the made changes. Please review. |
self.__get_action_id(post_resp), expect_errors=True | ||
) | ||
self.assertEqual(del_resp.status_int, 500) | ||
self.assertEqual(del_resp.json["faultstring"], msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a check to make sure that ACTION_1 is added back to the database?
@@ -264,6 +264,8 @@ def delete(self, ref_or_id, requester_user): | |||
"Exception was %s", | |||
e, | |||
) | |||
action_db.id = None | |||
Action.add_or_update(action_db) | |||
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if the deletion is related to permission error, can you change the error code to 403 Forbidden here? Otherwise for any other error, return 500 is fine.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Currently if PermissionError (or any other exception) occurs during removing files from disk, action delete operation deregisters the action from database but action files remains in filesystem i.e. this operation leaving st2 in an inconsistent state. So, it is required to rollback the operation and register action to database again if such case occurs.