Skip to content

Commit

Permalink
Merge 32caecf into d3e12d1
Browse files Browse the repository at this point in the history
  • Loading branch information
robgolding committed Jan 23, 2020
2 parents d3e12d1 + 32caecf commit ce71044
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tasklib/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import six
import subprocess
from functools import lru_cache

from .task import Task, TaskQuerySet, ReadOnlyDictView
from .filters import TaskWarriorFilter
Expand Down Expand Up @@ -321,6 +322,10 @@ def merge_with(self, path, push=False):
def undo(self):
self.execute_command(['undo'])

@lru_cache(maxsize=128)
def get_task(self, uuid):
return self.tasks.get(uuid=uuid)

# Backend interface implementation

def filter_tasks(self, filter_obj):
Expand Down
3 changes: 1 addition & 2 deletions tasklib/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def replace(self):
Performs conversion to the regular Task object, referenced by the
stored UUID.
"""

replacement = self._tw.tasks.get(uuid=self._uuid)
replacement = self._tw.get_task(self._uuid)
self.__class__ = replacement.__class__
self.__dict__ = replacement.__dict__

Expand Down
11 changes: 11 additions & 0 deletions tasklib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ def test_recurring_non_empty(self):
).save()
self.assertEqual(len(self.tw.tasks.recurring()), 1)

def test_get_task(self):
task = Task(self.tw, description='test task')
task.save()

fetched_task = self.tw.get_task(task['uuid'])
self.assertEqual(fetched_task, task)

# ensure `tw.tasks` is not queried as the task is cached
self.tw.tasks = None
self.tw.get_task(task['uuid'])

def test_filtering_by_attribute(self):
Task(self.tw, description='no priority task').save()
Task(self.tw, priority='H', description='high priority task').save()
Expand Down

0 comments on commit ce71044

Please sign in to comment.