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

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

Closed
ltbringer opened this issue Jun 27, 2022 · 0 comments
Closed

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

ltbringer opened this issue Jun 27, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ltbringer
Copy link
Contributor

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
@ltbringer ltbringer added the bug Something isn't working label Jun 27, 2022
ltbringer added a commit that referenced this issue Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant