Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confusing warning message when using custom mapping action #10236

Merged
merged 4 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nite catch! Do we also need a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be a good idea rather than relying on manual testing 😄 I'll create one now.

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