I have a common function which needs to be evaluated before executing all the KPIs. So I wrote a prepare function but prepare function is calling for all the KPIs separately. Instead I want a prepare function to be executed once for the each endpoint. My endpoint is like this
project-test:
pattern: /$YAMLURL/test
handler: FormHandler
kwargs:
auth: &AUTH
login_url: /$YAMLURL/login
kpi1:
prepare: validations.validate_request(args, handler)
url: $CONNECTION_STRING
queryfunction: queries.query1(args)
kpi2:
prepare: validations.validate_request(args, handler)
url: $CONNECTION_STRING
queryfunction: queries.query2(args)
modify: project.refactor(data, handler)
I tried to giving prepare function in the kwargs but getting
AttributeError: 'str' object has no attribute 'get'
The approach you shared is correct. The error may be in one of the custom functions, e.g.
validations.validate_request
,queries.query*
orproject.refactor
To test this, I created the following
data1.csv
... and
data2.csv
This is my
gramex.yaml
... and this is my
validations.py
:When I visit
/test
, the output only shows column 'a':... and the command prompt shows that the prepare function is called once for each dataset:
Perhaps you could share the full error message about where the AttributeError appeared? That might help.