Skip to content

Commit 78aa1b6

Browse files
committed
serialize_tags: make .filter(tags__contains='string') work
the example in readme says this example works, but actually it splits the argument by ',' unconditionally, expecting a list. so a string will be made into a "s,t,r,i,n,g". so we should handle getting passed either a single string and pass it through unchanged, or a list and join them actually if a list, we'd want to dedupe so we use a set which is the native type of the library for tags anyways
1 parent 793a86d commit 78aa1b6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tasklib has a similar API to that of Django's ORM::
3636
>>> tasks = tw.tasks.pending()
3737
>>> tasks
3838
['Tidy the house', 'Learn German']
39-
>>> tasks.filter(tags__contain='chores')
39+
>>> tasks.filter(tags__contains='chores')
4040
['Tidy the house']
4141
>>> type(tasks[0])
4242
<class 'tasklib.task.Task'>

tasklib/serializing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ def deserialize_annotations(self, data):
174174
return [TaskAnnotation(self, d) for d in data] if data else []
175175

176176
def serialize_tags(self, tags):
177-
return ','.join(tags) if tags else ''
177+
if isinstance(tags, list):
178+
tags = set(tags)
179+
if isinstance(tags, set):
180+
return ','.join(tags) if tags else ''
181+
if isinstance(tags, str):
182+
return tags
183+
raise ValueError("serialize_tags only supports list, set or string")
178184

179185
def deserialize_tags(self, tags):
180186
if isinstance(tags, str):

0 commit comments

Comments
 (0)