Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choice returns UnsupportedField when used with Field #619

Closed
cryocaustik opened this issue Jan 29, 2019 · 7 comments

Comments

Projects
None yet
2 participants
@cryocaustik
Copy link

commented Jan 29, 2019

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

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2019

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

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2019

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

@lk-geimfari lk-geimfari self-assigned this Jan 29, 2019

@lk-geimfari lk-geimfari pinned this issue Jan 29, 2019

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Jan 30, 2019

@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])
@cryocaustik

This comment has been minimized.

Copy link
Author

commented Feb 1, 2019

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

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Feb 1, 2019

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.

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Feb 2, 2019

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

@lk-geimfari

This comment has been minimized.

Copy link
Owner

commented Feb 2, 2019

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

@lk-geimfari lk-geimfari unpinned this issue Feb 2, 2019

@lk-geimfari lk-geimfari removed the help wanted label Feb 3, 2019

lk-geimfari added a commit that referenced this issue Mar 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.