Skip to content

Duckling can produce invalid dates for python like year=10000 #148

@ltbringer

Description

@ltbringer

Describe the bug
Duckling with latent entities enabled can produce invalid datetime for python.

To Reproduce

Run the following code:

from dialogy.plugins import DucklingPlugin


duckling_plugin = DucklingPlugin(dimensions=["time"])
x = duckling_plugin._get_entities_concurrent(["10000"], use_latent=True)

# here x would be:
[[{'body': '10000',
   'start': 0,
   'value': {'values': [{'value': '10000-01-01T00:00:00.000+00:00',
      'grain': 'year',
      'type': 'value'}],
    'value': '10000-01-01T00:00:00.000+00:00',
    'grain': 'year',
    'type': 'value'},
   'end': 5,
   'dim': 'time',
   'latent': True}]]

# now running
TimeEntity.from_duckling(x[0][0], 1).get_value()

# returns
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 t.get_value()

File ~/Programs/pythoncode/dialogy/dialogy/types/entity/time/__init__.py:113, in TimeEntity.get_value(self)
     96 """
     97 Return the date string in ISO format from the dictionary passed
     98 
   (...)
    110 :rtype: Optional[datetime]
    111 """
    112 entity_date_value = super().get_value()
--> 113 return dt_from_isoformat(entity_date_value)

File ~/Programs/pythoncode/dialogy/dialogy/types/entity/time/__init__.py:69, in dt_from_isoformat(iso_datetime)
     65 def dt_from_isoformat(iso_datetime: str) -> datetime:
     66     """
     67     Converts an ISO-formatted datetime string to a datetime object.
     68     """
---> 69     return datetime.fromisoformat(iso_datetime)

ValueError: Invalid isoformat string: '10000-01-01T00:00:00.000+00:00'

Expected behavior
We shouldn't return entities that can't be parsed.

Desktop (please complete the following information):

  • Dialogy 0.9.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions