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: 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"), + ]