Skip to content

Commit

Permalink
Merge pull request #8648 from RasaHQ/8587-yaml-reader-sentryfix
Browse files Browse the repository at this point in the history
Check for missing intent value in stories and rules and raise exception
  • Loading branch information
ancalita authored May 18, 2021
2 parents 46dde7a + f642c60 commit 2f869ca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/8587.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch `AttributeError` when reading stories or rules in YAML format and raise warning when intent value is missing in stories or rules.
7 changes: 7 additions & 0 deletions data/test_yaml_stories/rules_missing_intent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2.0"

rules:
- rule: greet user
steps:
- intent:
- action: utter_greet
7 changes: 7 additions & 0 deletions data/test_yaml_stories/stories_missing_intent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2.0"

stories:
- story: greet user
steps:
- intent:
- action: utter_greet
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ def _parse_or_statement(self, step: Dict[Text, Any]) -> None:
def _user_intent_from_step(
self, step: Dict[Text, Any]
) -> Tuple[Text, Optional[Text]]:
user_intent = step.get(KEY_USER_INTENT, "").strip()
try:
user_intent = step.get(KEY_USER_INTENT, "").strip()
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} .",
docs=self._get_docs_link(),
)
user_intent = ""

if not user_intent and KEY_USER_MESSAGE not in step:
rasa.shared.utils.io.raise_warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,19 @@ def test_read_from_file_skip_validation(monkeypatch: MonkeyPatch):
_ = reader.read_from_file(yaml_file, skip_validation=False)

assert reader.read_from_file(yaml_file, skip_validation=True) == []


@pytest.mark.parametrize(
"file",
[
"data/test_yaml_stories/rules_missing_intent.yml",
"data/test_yaml_stories/stories_missing_intent.yml",
],
)
def test_raises_exception_missing_intent_in_rules(file: Text, domain: Domain):
reader = YAMLStoryReader(domain)

with pytest.warns(UserWarning) as warning:
reader.read_from_file(file)

assert "Missing intent value" in warning[0].message.args[0]

0 comments on commit 2f869ca

Please sign in to comment.