snipsco/hermes-protocol

[hermes-python] AttributeError: 'TimeIntervalValue' object has no attribute 'slot_value'

koenvervloesem opened this issue · 2 comments

With Hermes Python 0.3.3, my apps work fine (build 49). For instance:

date = intent_message.slots.calendar_date.first()

With Hermes Python 0.4.0, the same code fails (build 48) with the following message:

  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/hermes_python/ontology/dialogue/slot.py", line 63, in first
    return self[0].slot_value.value
AttributeError: 'TimeIntervalValue' object has no attribute 'slot_value'

Using the method first() on CustomValue and InstantTimeValue results in the same error message, and I guess other slot types too. The relevant build log parts from my Travis CI:

$ coverage run test_action_what_is_happening.py
....E.EE.
======================================================================
ERROR: test_get_calendar_from_intent_with_calendar (__main__.TestTools)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_action_what_is_happening.py", line 120, in test_get_calendar_from_intent_with_calendar
    self.assertEqual(tools.get_calendar(intent_message, ""), "computer")
  File "/home/travis/build/koenvervloesem/snips-app-what-is-happening/tools_what_is_happening.py", line 23, in get_calendar
    calendar = str(intent_message.slots.calendar_file.first().value)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/hermes_python/ontology/dialogue/slot.py", line 63, in first
    return self[0].slot_value.value
AttributeError: 'CustomValue' object has no attribute 'slot_value'
======================================================================
ERROR: test_get_date_from_intent_with_interval (__main__.TestTools)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_action_what_is_happening.py", line 164, in test_get_date_from_intent_with_interval
    self.assertEqual(tools.get_date(intent_message), "20181105")
  File "/home/travis/build/koenvervloesem/snips-app-what-is-happening/tools_what_is_happening.py", line 47, in get_date
    date = intent_message.slots.calendar_date.first()
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/hermes_python/ontology/dialogue/slot.py", line 63, in first
    return self[0].slot_value.value
AttributeError: 'TimeIntervalValue' object has no attribute 'slot_value'
======================================================================
ERROR: test_get_date_from_intent_with_time (__main__.TestTools)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_action_what_is_happening.py", line 144, in test_get_date_from_intent_with_time
    self.assertEqual(tools.get_date(intent_message), "20181031")
  File "/home/travis/build/koenvervloesem/snips-app-what-is-happening/tools_what_is_happening.py", line 47, in get_date
    date = intent_message.slots.calendar_date.first()
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/hermes_python/ontology/dialogue/slot.py", line 63, in first
    return self[0].slot_value.value
AttributeError: 'InstantTimeValue' object has no attribute 'slot_value'
----------------------------------------------------------------------
Ran 9 tests in 0.153s
FAILED (errors=3)
The command "coverage run test_action_what_is_happening.py" exited with 1.

Hi @koenvervloesem !

I quickly read your tests cases and noticed an error (https://github.com/koenvervloesem/snips-app-what-is-happening/blob/master/test_action_what_is_happening.py#L130)

slot_map = SlotMap({"calendar_date": SlotsList([calendar_date_value])})

should be :

slot_map = SlotMap({"calendar_date":SlotsList([NluSlot(...) ])})

SlotsList should contain NluSlot objects, thus the errors you are seeing.

Still, I've noticed some weird behaviour trying to reproduce your errors.
I checked out at this commit, and running the tests give me an error :

➜  snips-app-what-is-happening git:(8b74012) ✗ coverage run test_action_what_is_happening.py
.F.F.....
======================================================================
FAIL: test_events_with_asterisk (__main__.TestCalendarCommand)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_action_what_is_happening.py", line 49, in test_events_with_asterisk
    self.assertEqual(len(events), 2)
AssertionError: 3 != 2

======================================================================
FAIL: test_multiline_events (__main__.TestCalendarCommand)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_action_what_is_happening.py", line 66, in test_multiline_events
    self.assertEqual(len(events), 4)
AssertionError: 10 != 4

----------------------------------------------------------------------
Ran 9 tests in 0.099s

FAILED (failures=2)

So I don't understand why your CI was successful while it should have errored even before this ...

Hi @anthonyray
Thanks for having a look at this! I created these tests when I didn't know the Hermes Python API that well, so they are a bit messy. I probably should rewrite them with the knowledge that I have now.

The errors you're seeing are probably because the calendar command outputs other values than in my test environment. I have it too when I don't set LANG=C on my machine with Dutch language settings.

Anyway, it looks like the error is in my tests and not in Hermes Python. I'll close this issue for now.