emmett
emmett copied to clipboard
Bug with 'in': {'dbset': ...} validation
I have this validation
'f1': {'in': {'dbset': lambda db: db.where(db.A.f2 == session.f2)}}
In another way:
def val_f2(db):
print(session.f2)
return db.where(db.A.f2 == session.f2)
'f1': {'in': {'dbset': lambda db: val_f2(db)}}
The problem I have is that lambda runs only once and after that first time does not come to run, then it is always calling db.where from the first condition. I can check it with the print() that only runs once
Jose
Or if it is not a bug, how can I do this dynamically?
@josejachuf I'm sorry, but I'm not sure I got the issue.
What do you mean by
lambda runs only once and after that first time does not come to run, then it is always calling db.where from the first condition
Can you explain it differently?
Hi @gi0baro
I hoped that by changing the value of session.f2 Validation is dynamic and contextual to what contains the value of session.f2.
About lambda, I thought that every time the validation was executed, I was going to take the conditions of the value of session.f2
Jose
@josejachuf so, theoretically speaking, the validation functions get called every time you pass a value for the relevant field. Also theoretically speaking, the session values should be the ones part of the dedicated request. Then, if something doesn't work in this way, there's a bug and I will investigate.
Nevertheless, under an architecting point of view, I strongly disagree with the principle of binding models with requests, for a couple of reasons:
- MVC strongly identifies roles of the tree components, and users' sessions are not part of the M part
- biding models to sessions implicitly means you wouldn't be able to perform operations on such models outside of the request flow (background jobs, shell, etc.)
So IMHO the validation logics performed against users, or in general the request flow should be made in the C part of MVC paradigm, which means routes or pipes in Emmett.
thanks @gi0baro for the info.
I ended up resolving as you say in the controller.
Jose