Skip to content
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

Merged
merged 4 commits into from
Sep 14, 2021

Conversation

mahesh-orch
Copy link
Contributor

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.

@pull-request-size pull-request-size bot added the size/XS PR that changes 0-9 lines. Quick fix/merge. label Sep 2, 2021
@m4dcoder m4dcoder added this to the 3.6.0 milestone Sep 2, 2021
@@ -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)
Copy link
Contributor

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)
Copy link
Contributor

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 m4dcoder linked an issue Sep 2, 2021 that may be closed by this pull request
@pull-request-size pull-request-size bot added size/S PR that changes 10-29 lines. Very easy to review. and removed size/XS PR that changes 0-9 lines. Quick fix/merge. labels Sep 3, 2021
@mahesh-orch
Copy link
Contributor Author

@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)
Copy link
Contributor

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))
Copy link
Contributor

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.

@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/S PR that changes 10-29 lines. Very easy to review. labels Sep 6, 2021
@CLAassistant
Copy link

CLAassistant commented Sep 6, 2021

CLA assistant check
All committers have signed the CLA.

@mahesh-orch
Copy link
Contributor Author

@m4dcoder

  • Unit test has been updated for checking action is getting re-registered to database in case of permission error. Also, separate unit test added for any other exception and action added to database.
  • Error code has changed to 403 (Forbidden) in case of permission error.
    Please review. Thanks.

Copy link
Contributor

@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@m4dcoder m4dcoder merged commit 4794e56 into StackStorm:master Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M PR that changes 30-99 lines. Good size to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Rework PR #5304 support for action file deletion.
4 participants