Skip to content

Commit

Permalink
Merge pull request #8684 from RasaHQ/8590-required-slots
Browse files Browse the repository at this point in the history
Handle empty slot mappings in domain forms
  • Loading branch information
ancalita authored May 18, 2021
2 parents 6a78bdc + 3902211 commit 46dde7a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/8590.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle `AttributeError ` thrown by empty slot mappings in domain form through refactoring.
6 changes: 5 additions & 1 deletion rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,11 @@ def slot_mapping_for_form(self, form_name: Text) -> Dict[Text, Any]:
Returns:
The slot mapping or an empty dictionary in case no mapping was found.
"""
return self.forms.get(form_name, {})[REQUIRED_SLOTS_KEY]
form = self.forms.get(form_name)
if form:
return form[REQUIRED_SLOTS_KEY]

return {}


class SlotMapping(Enum):
Expand Down
23 changes: 23 additions & 0 deletions tests/shared/core/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,3 +1424,26 @@ def test_domain_count_conditional_response_variations():
)
count_conditional_responses = domain.count_conditional_response_variations()
assert count_conditional_responses == 5


def test_domain_with_no_form_slots():
domain = Domain.from_yaml(
"""
version: "2.0"
forms:
contract_form:
"""
)
assert domain.slot_mapping_for_form("contract_form") == {}


def test_domain_with_empty_required_slots():
with pytest.raises(InvalidDomain):
Domain.from_yaml(
"""
version: "2.0"
forms:
contract_form:
required_slots:
"""
)

0 comments on commit 46dde7a

Please sign in to comment.