From b7a10933a859dbf2495ee980150652701b12cf51 Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Tue, 16 Nov 2021 11:59:21 +0000 Subject: [PATCH 1/2] fix cause behind confusing warning message --- rasa/core/actions/action.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rasa/core/actions/action.py b/rasa/core/actions/action.py index e99615293bb1..dcc2923089be 100644 --- a/rasa/core/actions/action.py +++ b/rasa/core/actions/action.py @@ -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: From 01b267f0919486c9a33a3d7cdc4ed3dc3ce7f076 Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Tue, 16 Nov 2021 14:17:53 +0000 Subject: [PATCH 2/2] add test --- tests/core/test_actions.py | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/core/test_actions.py b/tests/core/test_actions.py index a52ba75a4720..21e531cd2f41 100644 --- a/tests/core/test_actions.py +++ b/tests/core/test_actions.py @@ -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"), + ]