# Buggy code
def _apply_tokenizer_to_states(tokenizer: Tokenizer, states: List[State]) -> None:
    """Split each user text into tokens and concatenate them again.

    Args:
        tokenizer: A tokenizer to tokenize the user messages.
        states: The states to be tokenized.
    """
    for state in states:
        if USER in state:
            state[USER][TEXT] = " ".join(
                token.text
                for token in tokenizer.tokenize(
                    Message({TEXT: state[USER][TEXT]}), TEXT
                )
            )


# Traceback (KeyError)
(ihi2) D:\GitLab\IHI\rasa-bot>rasa data validate
2020-12-18 14:58:36.368767: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll


2020-12-18 14:58:40.702200: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-18 14:58:40.946225: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: GeForce GTX 1080 computeCapability: 6.1
coreClock: 1.7335GHz coreCount: 20 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 298.32GiB/s
2020-12-18 14:58:40.957226: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 1 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 980 computeCapability: 5.2
coreClock: 1.2155GHz coreCount: 16 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 208.91GiB/s
2020-12-18 14:58:40.963226: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-12-18 14:58:40.973227: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2020-12-18 14:58:40.981228: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-12-18 14:58:40.986229: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-12-18 14:58:40.998230: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2020-12-18 14:58:41.004231: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2020-12-18 14:58:41.014232: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2020-12-18 14:58:41.042234: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0, 1
2020-12-18 14:58:44 INFO     rasa.validator  - Validating intents...
2020-12-18 14:58:44 INFO     rasa.validator  - Validating uniqueness of intents and stories...
2020-12-18 14:58:44 INFO     rasa.validator  - Validating utterances...
2020-12-18 14:58:44 INFO     rasa.validator  - Story structure validation...
Processed story blocks: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 999.83it/s, # trackers=1]
2020-12-18 14:58:44 INFO     rasa.core.training.story_conflict  - Considering all preceding turns for conflict analysis.
2020-12-18 14:58:44 INFO     rasa.nlu.utils.spacy_utils  - Trying to load spacy model with name 'en_core_web_lg'
2020-12-18 14:59:00 INFO     rasa.nlu.components  - Added 'SpacyNLP' to component cache. Key 'SpacyNLP-en_core_web_lg'.
Traceback (most recent call last):
File "c:\programdata\anaconda3\envs\ihi2\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\programdata\anaconda3\envs\ihi2\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\envs\ihi2\Scripts\rasa.exe\__main__.py", line 7, in <module>
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\__main__.py", line 116, in main
cmdline_arguments.func(cmdline_arguments)
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\cli\data.py", line 262, in validate_files
and _validate_story_structure(validator, args)
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\cli\data.py", line 297, in _validate_story_structure
not args.fail_on_warnings, max_history=args.max_history
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\validator.py", line 249, in verify_story_structure
trackers, self.domain, max_history, self.nlu_config
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\core\training\story_conflict.py", line 185, in find_story_conflicts
trackers, domain, max_history, tokenizer
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\core\training\story_conflict.py", line 245, in _find_conflicting_states
for element in _sliced_states_iterator(trackers, domain, max_history, tokenizer):
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\core\training\story_conflict.py", line 333, in _sliced_states_iterator
_apply_tokenizer_to_states(tokenizer, sliced_states)
File "c:\programdata\anaconda3\envs\ihi2\lib\site-packages\rasa\core\training\story_conflict.py", line 351, in _apply_tokenizer_to_states
Message({TEXT: state[USER][TEXT]}), TEXT
KeyError: 'text'

# Fixed code
def _apply_tokenizer_to_states(tokenizer: Tokenizer, states: List[State]) -> None:
    """Split each user text into tokens and concatenate them again.

    Args:
        tokenizer: A tokenizer to tokenize the user messages.
        states: The states to be tokenized.
    """
    for state in states:
        if USER in state and TEXT in state[USER]:
            state[USER][TEXT] = " ".join(
                token.text
                for token in tokenizer.tokenize(
                    Message({TEXT: state[USER][TEXT]}), TEXT
                )
            )