Closed erikcw closed 11 years ago
Hi @erikcw!
Thanks for report the issue! Although it isn't really a bug in Booby, but rather a tricky behavior of the python's arguments default values, as explained in your link.
Anyway this should be fixed in some way in Booby, so I just added support to pass callable objects as a field default argument. When using callables as default, the default value of the field will be the callable return value.
Now, for example, you could do something like Field(default=list)
or Field(default=lambda: [])
to achieve the expected behavior.
I think this is the clearest way to solve that problem. Anyway, suggestions are welcome ;)
The docs suggest using an empty list for the default value of a field with a list of models as its validator.
Unfortunately, this will lead to undesirable behavior if the user tries to append models to an instance of the model containing the list field.
Background: http://effbot.org/zone/default-values.htm
From IPython:
Notice how the output from
In[11]
contains[{'a': 'a1'}]
instead of the anticipated[]
.Ideally and ListField would be added to the library as a work around. But at the very least the docs should be changed so that this isn't promoted.