ManyToMany field does not take dynamic initial values into account
|Reported by:||fas||Owned by:||fas|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Severity:||Keywords:||ManyToMany, initial, dynamic, lambda|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
For dbfields it is possible to provide the initial value in form of a anonymous function, e.g. models.CharField(..., initial=lambda: "I am dynamic!").
The formfield method of the ManyToMany field does not take this into account:
defaults['initial'] = [i._get_pk_val() for i in defaults['initial']]
The fix is simple and provided in a patch, diffed against release 1.0.2.
Change History (10)
comment:2 Changed 8 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|