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 crashes when having an association called "association" #2704

Closed
spieker opened this issue Aug 26, 2011 · 11 comments
Closed

ActiveRecord crashes when having an association called "association" #2704

spieker opened this issue Aug 26, 2011 · 11 comments

Comments

@spieker
Copy link

spieker commented Aug 26, 2011

Having an association called "association" on an ActiveRecord model results in a "SystemStackError: stack level too deep" exception. Using WEBrick this results in an "Illegal instruction"

@swanandp
Copy link
Contributor

Wouldn't association be a reserved word, and hence cannot be used as an association name?

@spieker
Copy link
Author

spieker commented Aug 26, 2011

Seems not. I try to upgrade an application to use rails 3.1 and it has an association with this name. To find the bug costs some time so it would be great if rails tells the user that it is a reserved word, this would save a lot of time, I think.

@dmathieu
Copy link
Contributor

There is an instance method association for every ActiveRecord object defined here :
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L152
Which was implemented in 1644663

So yes, in 3.1, the word association is reserved.

@spieker
Copy link
Author

spieker commented Aug 27, 2011

Would be great, if rails warns me if I define an association called "association"

@silviorelli
Copy link

Spent 2 days debugging the same issue.
Any sugestion on an updated list of reserved words for Rails 3.1.x?
'association' was not reserved in Rails 3.0.x

@ahawkins
Copy link

@spieker sounds very handy. @rafaelfranca what do you think of a PR for this?

@rafaelfranca
Copy link
Member

I think that would be great. Let try to fix it.

@sobko
Copy link

sobko commented May 18, 2012

I'm a teacher. The second rails app I made, I tried to name a model "Class". Made sense to me at the time. Didn't work. Didn't file a bug report, either. Filed it away under "things learned about Rails."

@schneems
Copy link
Member

What is the status on this? Has the issue been fixed via another PR? Having reserved keywords raise errors would be ideal, while it might make sense after the fact debugging the first time you run into the problem can be tricky. Tracking this in code would be a good way to clarify if scenarios like this were reserved keywords are added in fully realized this side effect.

@carlosantoniodasilva
Copy link
Member

I don't think anything has been merged lately related to this no.

In any case, it seems hard to handle every possibility, since you're technically not supposed to override any of the methods in ActiveRecord::Base, otherwise you'd be killing parts of the functionality - or getting booms. Perhaps, but just perhaps, as associaton called association could be an exception and could be handled, but the list of exceptions, starting by this one, would just increase I guess.

Btw, I know that scopes when created were doing this check, not sure they still do that in master (haven't checked again).

@steveklabnik
Copy link
Member

This is essentially a feature request. I'd love to have some specific cases merged, but it'll be near impossible to get perfect, and so I'm closing this. If you'd like to improve this aspect of rails, please submit a pull request: @schneems has improved several error messages lately. Thanks.

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

10 participants