From: Tomas Babej Date: Sat, 3 Jan 2015 11:16:31 +0000 (+0100) Subject: Task: Check that we are unable to set read only values through __init__ X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/faa9531194cd3657ce1e2f40e6e8067ac546958c?ds=sidebyside;hp=-c Task: Check that we are unable to set read only values through __init__ --- faa9531194cd3657ce1e2f40e6e8067ac546958c diff --git a/tasklib/task.py b/tasklib/task.py index f7afbf2..3a58e50 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -132,6 +132,11 @@ class Task(TaskResource): def __init__(self, warrior, **kwargs): self.warrior = warrior + # Check that user is not able to set read-only value in __init__ + for key in kwargs.keys(): + if key in self.read_only_fields: + raise RuntimeError('Field \'%s\' is read-only' % key) + # We serialize the data in kwargs so that users of the library # do not have to pass different data formats via __setitem__ and # __init__ methods, that would be confusing