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

Check for missing intent value in stories and rules and raise exception #8648

Merged
merged 8 commits into from
May 18, 2021

Conversation

ancalita
Copy link
Member

@ancalita ancalita commented May 10, 2021

Proposed changes:

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)

@ancalita ancalita requested a review from wochinge May 10, 2021 14:38
@@ -0,0 +1 @@
Catch AttributeError in YamlStoryReader method when intent value is missing in stories or rules and re-raise as RasaException.
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: Users probably don't know the YAMLStoryReaderr so I'd not expose the information to them and make it a bit easier to understand.

Suggested change
Catch AttributeError in YamlStoryReader method when intent value is missing in stories or rules and re-raise as RasaException.
Catch `AttributeError` when reading stories in YAML format when intent value is missing in stories or rules and re-raise as `RasaException`.

Copy link
Contributor

Choose a reason for hiding this comment

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

should this really be a misc changelog as it doesn't really affect the users?



def test_raises_exception_missing_intent_in_rules(domain: Domain):
rules = "data/test_yaml_stories/rules_missing_intent.yml"
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: I'd slightly prefer to inline the stories because it makes the tests easier to read (I don't have to jump to the file to understand the test

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remember this for future tests 👍

assert "Missing intent value" in str(e.value)


def test_raises_exception_missing_intent_in_stories(domain: Domain):
Copy link
Contributor

Choose a reason for hiding this comment

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

how about using pytest.mark.parametrize for these two?

Comment on lines 365 to 371
try:
user_intent = step.get(KEY_USER_INTENT, "").strip()
except AttributeError as e:
raise RasaException(
f"Missing intent value in {self._get_item_title()} step: {step} "
f"in '{self.source_name}'"
) from e
Copy link
Contributor

Choose a reason for hiding this comment

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

should we actually raise or treat this the same as the warning a few lines ahead? We don't raise for any other case so keeping it a warning seems more consistent to me

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I can change that - the question I have, when I use raise_warning would the next lines of code execute or do I need to add an empty return statement to stop the execution once this warning was raised?

Copy link
Contributor

Choose a reason for hiding this comment

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

The next lines of code would execute. raise_warning should probably rather be something like print_warning to avoid that confusion

@ancalita ancalita requested a review from wochinge May 17, 2021 10:45
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.

💯

except AttributeError:
rasa.shared.utils.io.raise_warning(
f"Issue found in '{self.source_name}':\n"
f"Missing intent value in {self._get_item_title()} step: {step} ."
Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding a link to the docs?

@ancalita ancalita merged commit 2f869ca into 2.6.x May 18, 2021
@ancalita ancalita deleted the 8587-yaml-reader-sentryfix branch May 18, 2021 08:55
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.

Gracefully handle when intents in stories.yml or rules.yml have no value
2 participants