Referring to this answer, I have defined the schema in a separate config file and using the read_config
function to read the schema. This works fine for standard validation rules but when I define fmt_date
I am getting malformed node or string on line 1: <ast.Name object at 0x123e36ad0>
error when calling the read_config
function. How do I fix this error? I want the ability to define the schema in a config file so that I can parameterize the validation part.
def read_config(config_key: str):
cParser = configparser.RawConfigParser()
cFilePath = r'config'
cParser.read(cFilePath)
return str(cParser.get('my-config', config_key))
doc_schema = ast.literal_eval(read_config('my_schema')) #getting error
v = Validator(doc_schema)
fmt_date = lambda s: datetime.strptime(s, '%Y-%m-%d')
Schema
[my-config]
my_schema = {"start_date": {"required": True, "nullable": True, "type": "datetime", "coerce": fmt_date}