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
Raise error when generating attribute with dangerous name #47752
Conversation
7ff68ef
to
8e24add
Compare
8e24add
to
7c2debd
Compare
def unknown_type?(type) | ||
type && | ||
DEFAULT_TYPES.exclude?(type.to_s) && | ||
! ActiveRecord::Base.connection.valid_type?(type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It hard to read the use of exclude?
in multiple conditions to me.
Let's keep it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kamipo. I've reverted the refactoring.
f92d1c5
to
ea6ce15
Compare
Generating a model with attributes named `hash` or `save` should raise an error, instead of generating a migration with an invalid attribute.
ea6ce15
to
99b1316
Compare
I just ran into an issue caused by this change in the view_component project. Our preview generator defines an Unfortunately, view_component's test suite doesn't have activerecord configured, so it blows up with:
I tried requiring activerecord in the dummy app, but doing so means we have to install and configure a database, which I'd rather not do. The bigger issue in my mind is that the change in this PR perhaps inadvertently couples the Rails generator code to activerecord, which not all apps have set up. Moreover, generated attributes are not just an activerecord thing as our preview generator demonstrates. Perhaps we could move |
Actually, coupling with activerecord has happened before at #42311. rails/railties/lib/rails/generators/named_base.rb Lines 196 to 198 in 83f36d5
|
Yes. We should. @p8 mind to open a PR? |
@rafaelfranca I've created a PR. |
Generating a model with attributes named
hash
orsave
should raise an error, instead of generating a migration with an invalid attribute.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]