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

if custom utter message contains no value or integer value then rasa fails returning custom utter message #5453

Closed
keremcadirci opened this issue Mar 20, 2020 · 2 comments · Fixed by #5875
Labels
type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@keremcadirci
Copy link

Rasa version: 1.7.1

Rasa SDK version (if used & relevant):

Rasa X version (if used & relevant):

Python version: 3.6.10

Operating system (windows, osx, ...): all

Issue:

when using custom utter message and custom utter response contains an empty value or a integer value rasa does not respond.
Custom utter response example:

    utter_sifre:
        - custom:
              type: category
              categoryType: QuickReply
              title: menu
              menu:
                  - title: menu1
                    img: 
                  - title: menu2
                    img: 

the attribute img above has no value or when an attribure has integer value like img: 2 the same issue occures
the error is the fallowing:

Error (including full traceback):

Encountered an exception while running action 'utter_sifre'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
2020-03-20 07:37:14 DEBUG    rasa.core.processor  - expected string or bytes-like object
Traceback (most recent call last):
  File "/build/lib/python3.6/site-packages/rasa/core/processor.py", line 564, in _run_action
    events = await action.run(output_channel, nlg, tracker, self.domain)
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
    return self.gen.send(None)
  File "/build/lib/python3.6/site-packages/rasa/core/actions/action.py", line 253, in run
    message = await nlg.generate(self.template_name, tracker, output_channel.name())
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
    return self.gen.send(None)
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 77, in generate
    template_name, filled_slots, output_channel, **kwargs
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 93, in generate_from_slots
    return self._fill_template(r, filled_slots, **kwargs)
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 119, in _fill_template
    template[key] = interpolate(template[key], template_vars)
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 51, in interpolate
    template[k] = [interpolate(i, values) for i in v]
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 51, in <listcomp>
    template[k] = [interpolate(i, values) for i in v]
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 53, in interpolate
    template[k] = interpolate_text(v, values)
  File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 17, in interpolate_text
    text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", template)
  File "/usr/local/lib/python3.6/re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
2020-03-20 07:37:14 DEBUG    rasa.core.processor  - Action 'utter_sifre' ended with events '[]'.

Command or request that led to error:


Content of configuration file (config.yml) (if relevant):

Content of domain file (domain.yml) (if relevant):

How we have solved the issue
we have modified the file rasa/rasa/core/nlg/interpolator.py :

def interpolate_text(template: Text, values: Dict[Text, Text]) -> Text:
    # transforming template tags from
    # "{tag_name}" to "{0[tag_name]}"
    # as described here:
    # https://stackoverflow.com/questions/7934620/python-dots-in-the-name-of-variable-in-a-format-string#comment9695339_7934969
    # black list character and make sure to not to allow
    # (a) newline in slot name
    # (b) { or } in slot name
    try:
        text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", template) 
        text = text.format(values)
        if "0[" in text:
            # regex replaced tag but format did not replace
            # likely cause would be that tag name was enclosed
            # in double curly and format func simply escaped it.
            # we don't want to return {0[SLOTNAME]} thus
            # restoring original value with { being escaped.
            return template.format({})

we have changed:
text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", template)
to
text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", str(template))

@keremcadirci keremcadirci added the type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors. label Mar 20, 2020
@erohmensing
Copy link
Contributor

Thanks for debugging @keremcadirci! Do you want to make a contribution to fix this bug?

@Archish27
Copy link
Contributor

@erohmensing Have created PR for this. Please review -> #5875

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
3 participants