Skip to content

Commit

Permalink
Merge branch 'main' into 10144/ValidationAction-fail-error
Browse files Browse the repository at this point in the history
  • Loading branch information
ancalita authored Nov 16, 2021
2 parents 6c035ae + 6153479 commit 1513df8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
20 changes: 11 additions & 9 deletions rasa/core/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def _create_back_up(
return original_content


def _update_mapping_condition(
def _get_updated_mapping_condition(
condition: Dict[Text, Text], mapping: Dict[Text, Any], slot_name: Text
) -> Dict[Text, Text]:
if mapping.get("type") not in [
str(SlotMapping.FROM_ENTITY),
str(SlotMapping.FROM_TRIGGER_INTENT),
]:
condition.update({REQUESTED_SLOT: slot_name})
return {**condition, REQUESTED_SLOT: slot_name}
return condition


Expand All @@ -53,20 +53,22 @@ def _get_updated_or_new_mappings(
conditions = existing_mapping.pop("conditions", [])
if existing_mapping in new_mappings:
new_mappings.remove(existing_mapping)

updated_condition = _update_mapping_condition(
condition, existing_mapping, slot_name
conditions.append(
_get_updated_mapping_condition(condition, existing_mapping, slot_name)
)

conditions.append(updated_condition)
existing_mapping.update({"conditions": conditions})
updated_mappings.append(existing_mapping)
else:
updated_mappings.append(mapping_copy)

for mapping in new_mappings:
updated_condition = _update_mapping_condition(condition, mapping, slot_name)
mapping.update({"conditions": [updated_condition]})
mapping.update(
{
"conditions": [
_get_updated_mapping_condition(condition, mapping, slot_name)
]
}
)
updated_mappings.append(mapping)

return updated_mappings
Expand Down
52 changes: 52 additions & 0 deletions tests/core/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,58 @@ def test_migrate_domain_format_with_custom_slot(tmp_path: Path, domain_out_file:
}


def test_migrate_domain_with_no_requested_slot_for_from_entity_mappings(
tmp_path: Path, domain_out_file: Path
):
existing_domain_file = prepare_domain_path(
tmp_path,
"""
version: "3.0"
intents:
- greet
- affirm
- inform
entities:
- city
slots:
location:
type: text
influence_conversation: false
email:
type: text
influence_conversation: false
forms:
some_form:
location:
- entity: city
type: from_entity
- intent: something
type: from_text
""",
"domain.yml",
)

rasa.core.migrate.migrate_domain_format(existing_domain_file, domain_out_file)

domain = Domain.from_path(domain_out_file)
assert domain

migrated_domain = rasa.shared.utils.io.read_yaml_file(domain_out_file)
migrated_slots = migrated_domain.get("slots")
location_slot = migrated_slots.get("location")
mappings = location_slot.get("mappings")
assert mappings[0] == {
"entity": "city",
"type": "from_entity",
"conditions": [{"active_loop": "some_form"}],
}
assert mappings[1] == {
"intent": "something",
"type": "from_text",
"conditions": [{"active_loop": "some_form", "requested_slot": "location"}],
}


def test_migrate_domain_format_duplicated_slots_in_forms(
tmp_path: Path, domain_out_file: Path
):
Expand Down

0 comments on commit 1513df8

Please sign in to comment.