I deployed a special validator for my ndb stringProperties to remove malicious code for my site.
def stringValidator(prop, value):
lowerValue = value.lower()
stripped = str(utils.escape(lowerValue))
if stripped != lowerValue:
raise datastore_errors.BadValueError(prop)
return stripped
Elsewhere, I will catch this error and return the failure to the client. I want to be able to return the type of a property that could not be verified.
except datastore_errors.BadValueError as err:
If I print(err), I get:
StringProperty('email', validator=<function stringValidator at 0x1079e11b8>)
I see that this StringProperty contains the name of the property that I want to return: 'email'. How to extract it?
EDIT: Dmitry gave me the most important half of the answer - to access the value of the error object after passing the property ._name, I need to use:
str(err.args[0])
source
share