Skip to content

Commit

Permalink
Merge pull request #10236 from RasaHQ/10144/ValidationAction-fail-error
Browse files Browse the repository at this point in the history
Fix confusing warning message when using custom mapping action
  • Loading branch information
ancalita authored Nov 16, 2021
2 parents 6153479 + 1513df8 commit 130405f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
8 changes: 3 additions & 5 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,11 +1026,9 @@ async def _run_custom_action(
output_channel, nlg, tracker, domain
)
for event in custom_events:
if (
isinstance(event, SlotSet)
and tracker.get_slot(event.key) != event.value
):
slot_events.append(event)
if isinstance(event, SlotSet):
if tracker.get_slot(event.key) != event.value:
slot_events.append(event)
elif isinstance(event, BotUttered):
slot_events.append(event)
else:
Expand Down
71 changes: 71 additions & 0 deletions tests/core/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2426,3 +2426,74 @@ async def test_action_extract_slots_returns_bot_uttered():
domain,
)
assert all([isinstance(event, (SlotSet, BotUttered)) for event in events])


async def test_action_extract_slots_does_not_raise_disallowed_warning_for_slot_events(
caplog: LogCaptureFixture,
):
domain_yaml = textwrap.dedent(
"""
version: "3.0"
slots:
custom_slot_a:
type: text
influence_conversation: false
mappings:
- type: custom
action: custom_extract_action
custom_slot_b:
type: text
influence_conversation: false
mappings:
- type: custom
actions:
- custom_extract_action
- action_validate_slot_mappings
"""
)
domain = Domain.from_yaml(domain_yaml)
event = UserUttered("Hi")
tracker = DialogueStateTracker.from_events(
sender_id="test_id", evts=[event], slots=domain.slots
)

action_server_url = "http:/my-action-server:5055/webhook"

with aioresponses() as mocked:
mocked.post(
action_server_url,
payload={
"events": [
{"event": "slot", "name": "custom_slot_a", "value": "test_A"},
]
},
)

mocked.post(
action_server_url,
payload={
"events": [
{"event": "slot", "name": "custom_slot_b", "value": "test_B"},
]
},
)

action_server = EndpointConfig(action_server_url)
action_extract_slots = ActionExtractSlots(action_server)

with caplog.at_level(logging.INFO):
events = await action_extract_slots.run(
CollectingOutputChannel(),
TemplatedNaturalLanguageGenerator(domain.responses),
tracker,
domain,
)

assert len(caplog.messages) == 0

assert events == [
SlotSet("custom_slot_b", "test_B"),
SlotSet("custom_slot_a", "test_A"),
]

0 comments on commit 130405f

Please sign in to comment.