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

Allow extra keys ignored after dict merge #24

Open
playpauseandstop opened this issue Dec 22, 2017 · 1 comment
Open

Allow extra keys ignored after dict merge #24

playpauseandstop opened this issue Dec 22, 2017 · 1 comment

Comments

@playpauseandstop
Copy link
Contributor

playpauseandstop commented Dec 22, 2017

Let me start with code,

In [1]: import trafaret as t

In [2]: td = t.Dict({'key': t.String()}).allow_extra('extra_key')

In [3]: td.merge(t.Dict({'other_key': t.String()})).check({'key': '1', 'extra_key': '2', 'other_key': '3'})
---------------------------------------------------------------------------
DataError                                 Traceback (most recent call last)
<ipython-input-3-84cf57110770> in <module>()
----> 1 td.merge(t.Dict({'other_key': t.String()})).check({'key': '1', 'extra_key': '2', 'other_key': '3'})

/usr/local/lib/python3.6/dist-packages/trafaret/base.py in check(self, value, context)
    116         """
    117         if hasattr(self, 'transform'):
--> 118             return self.transform(value, context=context)
    119         elif hasattr(self, 'check_value'):
    120             self.check_value(value)

/usr/local/lib/python3.6/dist-packages/trafaret/base.py in transform(self, value, context)
    990                         errors[key] = de
    991         if errors:
--> 992             raise DataError(error=errors, trafaret=self)
    993         return collect
    994 

DataError: {'extra_key': DataError(extra_key is not allowed key)}

From my point of view DataError is unexpected, but am I right it is raised due to logic reasons, that on merge you ignore all extra t.Dict rules to avoid errors on startup? E.g., when I'll try to merge some dict with key from .allow_extra?

If no and this is not intentional, I'd say it is a bug.

@Deepwalker
Copy link
Owner

Honestly this is a moment when I don't know. What behaviour is right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants