Skip to content
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

Bug with 'in': {'dbset': ...} validation #361

Open
josejachuf opened this issue Jul 5, 2021 · 5 comments
Open

Bug with 'in': {'dbset': ...} validation #361

josejachuf opened this issue Jul 5, 2021 · 5 comments

Comments

@josejachuf
Copy link

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

@josejachuf
Copy link
Author

Or if it is not a bug, how can I do this dynamically?

@gi0baro
Copy link
Member

gi0baro commented Jul 6, 2021

@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?

@josejachuf
Copy link
Author

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

@gi0baro
Copy link
Member

gi0baro commented Jul 7, 2021

@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.

@josejachuf
Copy link
Author

thanks @gi0baro for the info.

I ended up resolving as you say in the controller.

Jose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants