-
Notifications
You must be signed in to change notification settings - Fork 46
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
Make 'depends' field a little more tolerant of malformed data #155
base: develop
Are you sure you want to change the base?
Changes from all commits
4842eef
0a18f62
5014bf4
75a6f67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import absolute_import | ||
|
||
from distutils.version import LooseVersion | ||
|
||
import re | ||
import uuid | ||
|
||
from .base import DirtyableList, Field | ||
|
||
|
||
class DependsField(Field): | ||
version = LooseVersion('2.4') | ||
|
||
def deserialize(self, value): | ||
if not value: | ||
return DirtyableList([]) | ||
|
||
try: | ||
# In task-2.5, this moved from a comma-separated string to a real list. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nevermind -- the linked doc there clearly says that in the future this might be converted to return a list. |
||
# here we allow a migration path where old splitable strings are | ||
# handled as well as newschool lists. | ||
value_list = value | ||
if hasattr(value_list, "split"): # It's not actually a list! | ||
value_list = value_list.split(",") | ||
|
||
return DirtyableList([uuid.UUID(v) for v in value_list]) | ||
except ValueError: | ||
dependency_finder = re.compile( | ||
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" | ||
) | ||
return DirtyableList( | ||
[uuid.UUID(v) for v in dependency_finder.findall(value)] | ||
) | ||
|
||
def serialize(self, value): | ||
if not value: | ||
value = [] | ||
|
||
if not hasattr(value, "__iter__"): | ||
raise ValueError("Value must be list or tuple, not %r." % value) | ||
|
||
if self.version < LooseVersion("2.5"): | ||
return ",".join([str(v) for v in value]) | ||
else: | ||
# We never hit this second code branch now. taskwarrior changed | ||
# API slightly in version 2.5, but we're just going to go with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually, looking at the field, they do specifically say that "in the future" this will be changed to be a list:
All I can say is that it's clearly not a list in at least 2.5.3 locally for myself. |
||
# backwards compatibility for now. | ||
# Some day we should switch wholesale to the new path. | ||
return [str(v) for v in value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this field since the name was potentially misleading, and given that we long ago made this field specific to the idiosyncrasies of 'depends', it's probably reasonable to name it to indicate that.