Skip to content

Choice returns UnsupportedField when used with Field #619

Description

@cryocaustik

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

Activity

  1. lk-geimfari commented on Jan 29, 2019

    @lk-geimfari
    Owner

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

  2. lk-geimfari commented on Jan 29, 2019

    @lk-geimfari
    Owner

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

  3. self-assigned this
    on Jan 29, 2019
  4. pinned this issue on Jan 29, 2019
  5. lk-geimfari commented on Jan 30, 2019

    @lk-geimfari
    Owner

    @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])
  6. cryocaustik commented on Feb 1, 2019

    @cryocaustik
    Author

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

  7. lk-geimfari commented on Feb 1, 2019

    @lk-geimfari
    Owner

    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.

  8. lk-geimfari commented on Feb 2, 2019

    @lk-geimfari
    Owner

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

  9. lk-geimfari commented on Feb 2, 2019

    @lk-geimfari
    Owner

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

  10. unpinned this issue on Feb 2, 2019
  11. added a commit that references this issue on Mar 17, 2019
    8d2b7ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugUnexpected behaviour and bugs

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions