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
Closed

Choice returns UnsupportedField when used with Field #619

cryocaustik opened this issue Jan 29, 2019 · 7 comments
Assignees
Labels

Comments

@cryocaustik
Copy link

@cryocaustik cryocaustik 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
Copy link
Owner

@lk-geimfari lk-geimfari commented Jan 29, 2019

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

@lk-geimfari
Copy link
Owner

@lk-geimfari lk-geimfari 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
Copy link
Owner

@lk-geimfari lk-geimfari 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
Copy link
Author

@cryocaustik cryocaustik commented Feb 1, 2019

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

@lk-geimfari
Copy link
Owner

@lk-geimfari lk-geimfari 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
Copy link
Owner

@lk-geimfari lk-geimfari commented Feb 2, 2019

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

@lk-geimfari
Copy link
Owner

@lk-geimfari lk-geimfari 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 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
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants