-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Do not skip custom validators if value is null and allowNull is true #9143
Comments
+1 |
1 similar comment
+1 |
I think atleast no validate state should not be tied to |
this also fits a use case i have |
After further thought on this issue and further investigations on sequelize's code: Current sequelize behavior is as followsIf the value of an attribute is How I think it should beIf the value of an attribute is But if the value is
Because of the last bullet point, this change would consist of a breaking change, because a few people's code could start throwing I will open a PR implementing the above changes soon (including documentation changes, of course). |
I know I'm late for this, but I think this PR does not make any sense. If you have a special case to validate your own model, then treat it as a special case with a model validation. |
Hi @dalepo, I'm sorry to hear that... Would you be willing to update your validators or will you end up rolling back to v4? As I said in the upgrade guide:
In other words, you can upgrade by adding a |
Hi @papb we probably are gonna roll back. Adding |
Of course you know your situation more than I do, but why would the |
This has been merged a long time ago now but I must say ideologically I agree with @dalepo. Attribute validators should only rely on themselves, and should not run if the attribute is null. |
In 2013, the pull request #601 was created to resolve some issues such as #270.
@tremby said (source)
Five years later, I would like to respectfully disagree. It should be an (opt-out, of course) option. Below I will present a situation where the mandatory aspect of this change is preventing me from doing what I want.
My use case is that I want to allow null only in some cases. Therefore, neither "always" (accomplished with
allowNull: true
) nor "never" (accomplished byallowNull: false
) suit me, and since PR #601 made this a definitive check, any attempt of providing custom validators don't work.When I attempt to create the instance giving null to that field, my custom validator above does not execute at all, no matter what value
allowNull
is set to.Therefore this should be an option instead of a forced behaviour.
The text was updated successfully, but these errors were encountered: