-
Notifications
You must be signed in to change notification settings - Fork 90
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
Not able to add additional fields to document #196
Comments
First thing the string validator is not valid in python 3, I rewrited the String_val class to work : class String_val(VAL.Validator):
def validate(self, value):
if not isinstance(value, str):
raise ValidationError("Field value must be a string")
return True And you're right, there is an issue with the validation, the following definition for validateField, in the file document.py, fix this issue def validateField(self, field):
"""Validatie a field"""
if field not in self.validators:
if not self.collection._validation['allow_foreign_fields']:
raise SchemaViolation(self.collection.__class__, field)
else:
return True
if field in self.store:
if isinstance(self.store[field], DocumentStore):
return self[field].validate()
if field in self.patchStore:
return self.validators[field].validate(self.patchStore[field])
else:
try:
return self.validators[field].validate(self.store[field])
except ValidationError as e:
raise ValidationError( "'%s' -> %s" % ( field, str(e)) )
except AttributeError:
if isinstance(self.validators[field], dict) and not isinstance(self.store[field], dict):
raise ValueError("Validator expected a sub document for field '%s', got '%s' instead" % (field, self.store[field]) )
else:
raise
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a document definition similar to this one:
`
class Humans(COL.Collection):
_properties = {
"keyOptions" : {
"allowUserKeys": False,
"type": "autoincrement",
"increment": 1,
"offset": 0,
}
}
`
---> 'allow_foreign_fields': True is set to True
When I create a document and want to add a field (remember ---> 'allow_foreign_fields': True) it throws an exception
---> 68 return self.validators[field].validate(self.patchStore[field])
69 else:
70 try:
KeyError: 'test'
I know, that it would change the schema... but I thought I have a validation part, that has to be there and an optional part...
How can this be reached? Thanks for support!
The text was updated successfully, but these errors were encountered: