Code Monkey home page Code Monkey logo

Comments (12)

funkyfuture avatar funkyfuture commented on July 23, 2024 1

hm, this doesn't fail.

what's actually the output of your code above?

from cerberus.

vinilios avatar vinilios commented on July 23, 2024

The _errors include the following,

{'info': {'name': 'required field'}}

This seems to got introduced with f66d8bd. This commit is not in your fork though and i guess that's why you don't get an error.

from cerberus.

CD3 avatar CD3 commented on July 23, 2024

I'm seeing the same problem.

I think the problem is in the __validate_required_fields function. There are two lines that get the set of missing fields.

required = list(field for field, definition in self.schema.items()
                      if definition.get('required') is True)
missing = set(required) - set(key for key in document.keys()
                                      if document.get(key) is not None or
                                      not self.ignore_none_values)

self.schema is the subdocument schema, but document is always coming in as the full dict being validated. So, the list of required keys is generated correctly for each level in a document, but then the keys in the top level of the document are checked instead of the keys at the correct level.

from cerberus.

CD3 avatar CD3 commented on July 23, 2024

If I revert self.document back to document, undoing commit f66d8bd, it fixes the error.

from cerberus.

funkyfuture avatar funkyfuture commented on July 23, 2024

well, i was the one that authored the commit in question. so, yes i'm actually using this code. can you please cherry-pick this commit and run the tests? it should fail. if not, please investigate.

i'm, too tired to hack around now.
but as @CD3 points at some interesting piece of code, my guess is that it could be rather caused because self.document is not referenced, but document.

here's my git log for comparison:

6f68def Adds a test for #107
e680644 Merge branch 'use-str.format-for-error-messages'
3213498 Changelog for #106
4936621 flake8
65e0093 use str.format
8c31395 Merge branch 'fix-usages-of-document-to-self.document'
3df80e9 Changelog for #103
20bdff7 Merge branch 'add-propertyschema-validation'
9752c8d Adds 'propertyschema'-validation rule.
f66d8bd Fixes usages of document to self.document in _validate  <- here it is.
7c37825 Merge branch 'add-wrapper-method-validate'
2ebc8e5 Improve 'validated' method visibility in the docs.
2c19edf Adds wrapper-method `validated`

from cerberus.

CD3 avatar CD3 commented on July 23, 2024

do you know why you made this change? the commit log doesn't say.

from cerberus.

funkyfuture avatar funkyfuture commented on July 23, 2024

yes, because with the introduction of coercion Validator_validate began working on a copy of the document. these were missing changes, as they referred still to the object that was passed to the method initially. and i still suspect more that has been overlooked like in __validate_required_fields.

but as long as i can't reproduce a fail, i won't investigate further. has anyone tried the test i added, and how does it behave?

from cerberus.

CD3 avatar CD3 commented on July 23, 2024

Now it does fail.

...
======================================================================
FAIL: test_issue_107 (cerberus.tests.tests.TestValidator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/cclark/build/cerberus/cerberus/tests/tests.py", line 861, in test_issue_107
    raise AssertionError("Document did not validate")
AssertionError: Document did not validate
----------------------------------------------------------------------
Ran 91 tests in 0.048s

Using self.assertSuccess works, creating a validator and giving a document to the validate function does not.

from cerberus.

funkyfuture avatar funkyfuture commented on July 23, 2024

thanks, i will look into it.

have you already figured out the reason why self.assertSuccess doesn't fail as it should? this is the first issue to tackle down.

from cerberus.

CD3 avatar CD3 commented on July 23, 2024

no, I have not been able to look it yet. it creates and used the validator differently,

    def assertSuccess(self, document, schema=None, validator=None):
        if validator is None:
            validator = self.validator
        self.assertTrue(validator.validate(document, schema, update=True),
                        validator.errors)

as opposed to just

        validator = Validator(schema)
        res = validator.validate(document)

which fails. There must be some difference in the setup between these two cases.

from cerberus.

isaulv avatar isaulv commented on July 23, 2024

I too am affected by this issue.
I have

{"mx": {"type": "list", "required": True,
                      "schema": {"type": "dict",
                                 "schema":{
                                    "from": {"type": "string", "required": True},
                                    "ip": {"type": "string", "required": True},
                                    "host": {"type": "string", "required": True},
                                    "procs": {"type": "integer", "required": True},
                                    "mta": {"type": "string", "required": True},
                                    "port": {"type": "string", "required": True}}}}}

as my schema and I get a similar error as the poster above.

from cerberus.

funkyfuture avatar funkyfuture commented on July 23, 2024

that's a nasty one, see #111 for some progress.

from cerberus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.