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

retry on PermissionError during data export #5922

Merged
merged 10 commits into from
Sep 29, 2020
Merged

retry on PermissionError during data export #5922

merged 10 commits into from
Sep 29, 2020

Conversation

Dobatymo
Copy link
Contributor

@Dobatymo Dobatymo commented Jun 1, 2020

Proposed changes:

I did not catch the error at the higher level, because then the individual files could not be retried and inconsistent data (like double appends) would be unavoidable.

This is my first pull request for this project. It would be great to have some feedback.

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@CLAassistant
Copy link

CLAassistant commented Jun 1, 2020

CLA assistant check
All committers have signed the CLA.

@sara-tagger
Copy link
Collaborator

Thanks for opening a draft pull request 🚀If you have any questions, you can direct them to @Ghostvv

@wochinge wochinge self-requested a review June 2, 2020 11:01
@wochinge wochinge self-assigned this Jun 10, 2020
Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

Thanks for your PR @Dobatymo 🎉

Can you please also add a changelog entry? 🙌

rasa/core/training/interactive.py Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
rasa/core/training/interactive.py Outdated Show resolved Hide resolved
@Dobatymo
Copy link
Contributor Author

I wasn't sure how to handle the questionary.confirm in a test, so I added a simple mock. Is that test enough?

Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

👍

rasa/core/training/interactive.py Outdated Show resolved Hide resolved
tests/core/training/test_interactive.py Outdated Show resolved Hide resolved

interactive.questionary.confirm = QuestionaryConfirmMock(3)

await interactive._retry_on_error(func, "export_path", True)
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: use a lambda for func. I think it's more clear what you're testing then (currently I have to follow the bool parameter and then see what func is supposed to do in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think lambdas would be clearer to read as well. However it is weird to raise exceptions from lambdas (lambda x: raise y) doesn't work and also argument passing is tested this way as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

optional: you could do something like this. Using the mock you could also test the passing of the args.

Suggested change
await interactive._retry_on_error(func, "export_path", True)
await interactive._retry_on_error(Mock(side_effect=PermissionError()), "export_path")

tests/core/training/test_interactive.py Outdated Show resolved Hide resolved
@Dobatymo
Copy link
Contributor Author

rebased

rasa/core/training/interactive.py Outdated Show resolved Hide resolved

interactive.questionary.confirm = QuestionaryConfirmMock(3)

await interactive._retry_on_error(func, "export_path", True)
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: you could do something like this. Using the mock you could also test the passing of the args.

Suggested change
await interactive._retry_on_error(func, "export_path", True)
await interactive._retry_on_error(Mock(side_effect=PermissionError()), "export_path")

@wochinge
Copy link
Contributor

@alwx Can you take over the review next week as I'm on vacation? Thanks 🙏

@alwx alwx self-requested a review September 18, 2020 07:29
@tmbo tmbo marked this pull request as ready for review September 26, 2020 11:38
@tmbo tmbo added this to the 2.0 Rasa Open Source milestone Sep 26, 2020
@tmbo
Copy link
Member

tmbo commented Sep 26, 2020

would be great to get this into the 2.0 release

tests/core/training/test_interactive.py Outdated Show resolved Hide resolved
tests/core/training/test_interactive.py Outdated Show resolved Hide resolved

m = Mock(side_effect=PermissionError())
with pytest.raises(PermissionError):
await interactive._retry_on_error(m, "export_path", 1, a=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await interactive._retry_on_error(m, "export_path", 1, a=2)
interactive._retry_on_error(m, "export_path", 1, a=2)

Comment on lines 650 to 660
m = Mock(side_effect=PermissionError())
with pytest.raises(PermissionError):
await interactive._retry_on_error(m, "export_path", 1, a=2)
c = call("export_path", 1, a=2)
m.assert_has_calls([c, c, c])
Copy link
Contributor

Choose a reason for hiding this comment

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

a unit test should always just test one case. I think it makes sense to move this to a separate test function with an appropriate name.

m = Mock(side_effect=PermissionError())
with pytest.raises(PermissionError):
await interactive._retry_on_error(m, "export_path", 1, a=2)
c = call("export_path", 1, a=2)
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 please refer to call by it's module name? This is a code convention of ours to make it very explicit at the first glance where a function is coming from

Suggested change
c = call("export_path", 1, a=2)
c = mock.call("export_path", 1, a=2)

@wochinge wochinge removed the request for review from alwx September 28, 2020 07:24
@wochinge wochinge merged commit 7fa018f into RasaHQ:master Sep 29, 2020
@wochinge
Copy link
Contributor

💯 @Dobatymo

@Dobatymo Dobatymo deleted the export-retry branch October 4, 2020 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants