Comments (12)
hm, this doesn't fail.
what's actually the output of your code above?
from cerberus.
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.
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.
If I revert self.document
back to document
, undoing commit f66d8bd
, it fixes the error.
from cerberus.
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.
do you know why you made this change? the commit log doesn't say.
from cerberus.
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.
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.
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.
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.
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.
that's a nasty one, see #111 for some progress.
from cerberus.
Related Issues (20)
- Unexpected normalization behavior with anyof_schema HOT 1
- Conditional validation for empty parameter
- Dependencies not being honored? HOT 1
- anyof does not respect nullable: True HOT 2
- install_requires=["setuptools"], in setup.py is wrong HOT 4
- Bug with rules_set_registry() for rule with type dict and included schema HOT 3
- Address DeprecationWarning errors to fix installation warning HOT 1
- Importing cerberus takes too long HOT 3
- Coercing fields does not work recursively HOT 2
- pyproject.toml does not specify requires-python HOT 1
- Rename and Coerce do not work together HOT 2
- anyof does not respect required: False HOT 4
- Inside oneof_schema not work default values for nested keys
- "anyof"/"oneof" and "nullable" do not behave as expected HOT 1
- ImportError: cannot import name 'Iterable' from 'collections' HOT 1
- Python 3.12 - SyntaxWarning HOT 1
- Dynamically set value for schema based on document values [Proposed label: feature_request
- Can't use 'oneof' for a list of complex elements
- Whitebox testing an error raising custom validation rule is not supported
- Custom data type validation does not support custom error generation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cerberus.