Mimesis: Choice returns UnsupportedField when used with Field

Created on 29 Jan 2019  路  7Comments  路  Source: lk-geimfari/mimesis

Bug report

What's wrong

I was attempting to use choice within Schema generation to pick from a list of options but ran into an UnsupportedField error.

It would appear that AbsrtractField returns UnsupportedField when used with on Choice provider.

Example:

>>> from mimesis.schema import Field, Schema
>>> _ = Field('en')
>>> _('choice', items=[1,2,3])
Traceback (most recent call last):
  File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 100, in __call__
    result = self._table[name](**kwargs)
KeyError: 'choice'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    _('choice', items=[1,2,3])
  File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 105, in __call__
    raise UnsupportedField(name)
mimesis.exceptions.UnsupportedField: Field 芦choice禄 is not supported.
>>> 

System information

Python version: 3.6.5
Mimesis version: 3.0.0
OS: Windows 10

bug

All 7 comments

Seems like a bug. Field and Schema use Generic which has an attribute choice, so it must work.

It happens because of implementation of Choice provider. We need to think about how to fix it.

@cryocaustik Here is a workaround if you really need to use it:

from mimesis.schema import Field, Schema
from mimesis.providers import Choice

class Choice(Choice):
    def choice(self, *args, **kwargs):
        return self.__call__(*args, **kwargs)


_ = Field('en', providers=(Choice,))

_('choice', items=[1, 3, 4])

Thanks! I ended doing something similar but with a custom provider.

I would like to fix that bug and create a new release, but I'm really extremely busy, so I hope that I can fix it on weekends.

So, this issue has been fixed. We will publish a release as soon as possible.

It's done. 3.1.0 has been released. Thanks for the bug report!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobolevn picture sobolevn  路  6Comments

lk-geimfari picture lk-geimfari  路  4Comments

lk-geimfari picture lk-geimfari  路  5Comments

lk-geimfari picture lk-geimfari  路  7Comments

jjgriff93 picture jjgriff93  路  5Comments