diff --git a/changelog/11433.bugfix.md b/changelog/11433.bugfix.md new file mode 100644 index 000000000000..852540d098ed --- /dev/null +++ b/changelog/11433.bugfix.md @@ -0,0 +1 @@ +This fix makes sure that when a Domain object is loaded from multiple files where one file specifies a custom session config and the rest do not, the default session configuration does not override the custom session config. diff --git a/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/config.yml b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/config.yml new file mode 100644 index 000000000000..6e9195534e75 --- /dev/null +++ b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/config.yml @@ -0,0 +1,39 @@ +recipe: default.v1 +language: en +pipeline: [] +# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model. +# # If you'd like to customize it, uncomment and adjust the pipeline. +# # See https://rasa.com/docs/rasa/tuning-your-model for more information. +# - name: WhitespaceTokenizer +# - name: RegexFeaturizer +# - name: LexicalSyntacticFeaturizer +# - name: CountVectorsFeaturizer +# - name: CountVectorsFeaturizer +# analyzer: char_wb +# min_ngram: 1 +# max_ngram: 4 +# - name: DIETClassifier +# epochs: 100 +# constrain_similarities: true +# - name: EntitySynonymMapper +# - name: ResponseSelector +# epochs: 100 +# constrain_similarities: true +# - name: FallbackClassifier +# threshold: 0.3 +# ambiguity_threshold: 0.1 + +data: +policies: +# # No configuration for policies was provided. The following default policies were used to train your model. +# # If you'd like to customize them, uncomment and adjust the policies. +# # See https://rasa.com/docs/rasa/policies for more information. +# - name: MemoizationPolicy +# - name: RulePolicy +# - name: UnexpecTEDIntentPolicy +# max_history: 5 +# epochs: 100 +# - name: TEDPolicy +# max_history: 5 +# epochs: 100 +# constrain_similarities: true diff --git a/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/nlu.yml b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/nlu.yml new file mode 100644 index 000000000000..2f6c3f8c7d3e --- /dev/null +++ b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/nlu.yml @@ -0,0 +1,91 @@ +version: "3.1" + +nlu: +- intent: greet + examples: | + - hey + - hello + - hi + - hello there + - good morning + - good evening + - moin + - hey there + - let's go + - hey dude + - goodmorning + - goodevening + - good afternoon + +- intent: goodbye + examples: | + - cu + - good by + - cee you later + - good night + - bye + - goodbye + - have a nice day + - see you around + - bye bye + - see you later + +- intent: affirm + examples: | + - yes + - y + - indeed + - of course + - that sounds good + - correct + +- intent: deny + examples: | + - no + - n + - never + - I don't think so + - don't like that + - no way + - not really + +- intent: mood_great + examples: | + - perfect + - great + - amazing + - feeling like a king + - wonderful + - I am feeling very good + - I am great + - I am amazing + - I am going to save the world + - super stoked + - extremely good + - so so perfect + - so good + - so perfect + +- intent: mood_unhappy + examples: | + - my day was horrible + - I am sad + - I don't feel very well + - I am disappointed + - super sad + - I'm so sad + - sad + - very sad + - unhappy + - not good + - not very good + - extremly sad + - so saad + - so sad + +- intent: bot_challenge + examples: | + - are you a bot? + - are you a human? + - am I talking to a bot? + - am I talking to a human? diff --git a/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/responses.yml b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/responses.yml new file mode 100644 index 000000000000..03929b32bf11 --- /dev/null +++ b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/responses.yml @@ -0,0 +1,6 @@ +version: "3.1" + + +responses: + utter_test: + - text: "Hey! How are you?" diff --git a/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/stories.yml b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/stories.yml new file mode 100644 index 000000000000..6ff78ee20864 --- /dev/null +++ b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/data/stories.yml @@ -0,0 +1,30 @@ +version: "3.1" + +stories: + +- story: happy path + steps: + - intent: greet + - action: utter_greet + - intent: mood_great + - action: utter_happy + +- story: sad path 1 + steps: + - intent: greet + - action: utter_greet + - intent: mood_unhappy + - action: utter_cheer_up + - action: utter_did_that_help + - intent: affirm + - action: utter_happy + +- story: sad path 2 + steps: + - intent: greet + - action: utter_greet + - intent: mood_unhappy + - action: utter_cheer_up + - action: utter_did_that_help + - intent: deny + - action: utter_goodbye diff --git a/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/domain.yml b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/domain.yml new file mode 100644 index 000000000000..751380631360 --- /dev/null +++ b/data/test_domains/test_domain_files_with_no_session_config_and_custom_session_config/domain.yml @@ -0,0 +1,34 @@ +version: "3.1" + +intents: + - greet + - goodbye + - affirm + - deny + - mood_great + - mood_unhappy + - bot_challenge + +responses: + utter_greet: + - text: "Hey! How are you?" + + utter_cheer_up: + - text: "Here is something to cheer you up:" + image: "https://i.imgur.com/nGF1K8f.jpg" + + utter_did_that_help: + - text: "Did that help you?" + + utter_happy: + - text: "Great, carry on!" + + utter_goodbye: + - text: "Bye" + + utter_iamabot: + - text: "I am a bot, powered by Rasa." + +session_config: + session_expiration_time: 0 + carry_over_slots_to_new_session: false diff --git a/rasa/shared/core/domain.py b/rasa/shared/core/domain.py index 4ab90f46768e..4ccbe8b1d4b5 100644 --- a/rasa/shared/core/domain.py +++ b/rasa/shared/core/domain.py @@ -339,7 +339,10 @@ def merge_domain_dicts( override or combined.get(SESSION_CONFIG_KEY) == SessionConfig.default().as_dict() or combined.get(SESSION_CONFIG_KEY) is None - ) and domain_dict.get(SESSION_CONFIG_KEY): + ) and domain_dict.get(SESSION_CONFIG_KEY) not in [ + None, + SessionConfig.default().as_dict(), + ]: combined[SESSION_CONFIG_KEY] = domain_dict[SESSION_CONFIG_KEY] # remove existing forms from new actions diff --git a/tests/regressions/test_domain_merge_multiple_files_with_custom_session_config_and_no_session_config.py b/tests/regressions/test_domain_merge_multiple_files_with_custom_session_config_and_no_session_config.py new file mode 100644 index 000000000000..a224b1341461 --- /dev/null +++ b/tests/regressions/test_domain_merge_multiple_files_with_custom_session_config_and_no_session_config.py @@ -0,0 +1,40 @@ +from rasa.shared.core.domain import SessionConfig +from rasa.shared.importers.importer import TrainingDataImporter + + +def test_merge_domain_with_custom_session_config_and_no_session_config(): + expected_session_expiration_time = 0 + expected_carry_over_slots = False + + config_path = ( + "data/test_domains/" + "test_domain_files_with_no_session_config_and_custom_session_config/config.yml" + ) + domain_path = ( + "data/test_domains/" + "test_domain_files_with_no_session_config_and_custom_session_config/domain.yml" + ) + training_data_paths = [ + "data/test_domains/" + "test_domain_files_with_no_session_config_and_custom_session_config/data" + ] + file_importer = TrainingDataImporter.load_from_config( + config_path, domain_path, training_data_paths + ) + + domain = file_importer.get_domain() + + assert ( + domain.session_config.session_expiration_time + != SessionConfig.default().session_expiration_time + ) + assert ( + domain.session_config.carry_over_slots + != SessionConfig.default().carry_over_slots + ) + + assert ( + domain.session_config.session_expiration_time + == expected_session_expiration_time + ) + assert domain.session_config.carry_over_slots == expected_carry_over_slots