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

ActiveRecord valid? should includes ActiveModel validation for integer type column #37256

Closed
baoqchau opened this issue Sep 20, 2019 · 5 comments

Comments

@baoqchau
Copy link

Steps to reproduce

https://gist.github.com/baoqchau/1ee3f2a1d11b4a006f1f2ab70451be62

Expected behavior

post.valid? should return false.

Actual behavior

post.valid? return true and then when you save it (post.save!) it will return the ActiveModel error. is out of range for ActiveModel::Type::Integer with limit 4 bytes,

System configuration

Rails version:
6.0.0
Ruby version:
2.6.3

@baoqchau baoqchau changed the title ActiveRecord valid? should includes ActiveModel validation ActiveRecord valid? should includes ActiveModel validation for integer type column Sep 20, 2019
@joshmn
Copy link
Contributor

joshmn commented Sep 20, 2019

Your example app doesn't have any validations in it, is this expected?

If you need to validate this, though, validates :number_of_comment, inclusion: (-2147483648..2147483648)

@baoqchau
Copy link
Author

Yeah I agree that I can add that validation, but should we have this validation shows when you check valid? or when you initialize it? If not, I think we should have a way to add this as a default validation for integer type field in ActiveRecord.

@allcentury
Copy link

This is a problem of database constraints vs app validations, take a read through https://thoughtbot.com/blog/validation-database-constraint-or-both. It is a tough problem but I'm not sure if rails has a precedent for this.

@wjessop
Copy link
Contributor

wjessop commented Sep 26, 2019

Looks to be the same issue as #37283

@kamipo
Copy link
Member

kamipo commented Sep 27, 2019

This is not an issue but like a proposal.
Since we reserve the issues tracker for issues only, use the Rails Core mailing list for feature requests.

@kamipo kamipo closed this as completed Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants