[patch] Field's choices can be "used" only once if its a generator or an iterator.
|Reported by:||Alex Dedul||Owned by:||adrian|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If you have field with an iterator/generator for choices its correct display value could be fetched only once. For example:
>>> from intranet.orders.models import SSL >>> s = SSL.objects.get(pk=1) >>> s.get_country_display() 'Belarus' >>> s.get_country_display() 'BY' >>> s.get_country_display() 'BY'
Its apparent that its because of the nature of iterators that can be "listed" only once. Proposed patch to fix this uses itertools.tee for every field.choices that looks like an iterator. Hardly its perfect, cos tee is caching values. Maybe someone could come up with a better solution.
Also there should be tests for this, but lets see what core devs says for now.