Skip to content

Commit

Permalink
Merge pull request #7564 from RasaHQ/fix-form-rejection
Browse files Browse the repository at this point in the history
ignore SlotSets for requested slots
  • Loading branch information
akelad authored Dec 17, 2020
2 parents 4c04739 + c4a3db5 commit 779b715
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog/7557.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a problem where a [form](forms.mdx) wouldn't reject when the
`FormValidationAction` re-implemented `required_slots`.
6 changes: 5 additions & 1 deletion rasa/core/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ async def validate(
)

some_slots_were_validated = any(
isinstance(event, SlotSet) for event in validation_events
isinstance(event, SlotSet)
for event in validation_events
# Ignore `SlotSet`s for `REQUESTED_SLOT` as that's not a slot which needs
# to be filled by the user.
if isinstance(event, SlotSet) and not event.key == REQUESTED_SLOT
)
user_rejected_manually = any(
isinstance(event, ActionExecutionRejected) for event in validation_events
Expand Down
15 changes: 13 additions & 2 deletions tests/core/actions/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,18 @@ async def test_validate_slots(
assert events == expected_events


async def test_no_slots_extracted_with_custom_slot_mappings():
@pytest.mark.parametrize(
"custom_events",
[
# Custom action returned no events
[],
# Custom action returned events but no `SlotSet` events
[BotUttered("some text").as_dict()],
# Custom action returned only `SlotSet` event for `required_slot`
[SlotSet(REQUESTED_SLOT, "some value").as_dict()],
],
)
async def test_no_slots_extracted_with_custom_slot_mappings(custom_events: List[Event]):
form_name = "my form"
events = [
ActiveLoop(form_name),
Expand All @@ -378,7 +389,7 @@ async def test_no_slots_extracted_with_custom_slot_mappings():
action_server_url = "http:/my-action-server:5055/webhook"

with aioresponses() as mocked:
mocked.post(action_server_url, payload={"events": []})
mocked.post(action_server_url, payload={"events": custom_events})

action_server = EndpointConfig(action_server_url)
action = FormAction(form_name, action_server)
Expand Down

0 comments on commit 779b715

Please sign in to comment.