Prevent creation of database columns with a reserved name #2629

Closed
marceldegraaf opened this Issue Aug 22, 2011 · 10 comments

Comments

Projects
None yet
5 participants
@marceldegraaf

Today I ran into this issue: apparently a database column with the name hash breaks things, resulting in a non-helpful error:

TypeError (can't convert String into Integer)

Creation of columns with reserved names should be prevented. If that is impossible, a more helpful error message would be awesome.

@ognevsky

This comment has been minimized.

Show comment Hide comment
@ognevsky

ognevsky Aug 22, 2011

Any other words except hash?

Any other words except hash?

@marceldegraaf

This comment has been minimized.

Show comment Hide comment
@marceldegraaf

marceldegraaf Aug 23, 2011

Not that I'm aware of, but I have no idea how to find out. All the reserved words lists I could find online seem to be hopelessly outdated.

This page has a comprehensive list, but it is from 2007:
http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails

There are two wiki entries that seem to deal with reserved words, but one is empty and the other only contains a dead link:
http://wiki.rubyonrails.org/rails/pages/ReservedWords (has dead link)
http://wiki.rubyonrails.org/rails/pages/MagicFieldNames (is empty)

I could find no mention of reserved column names in the Rails Guides as well.

Not that I'm aware of, but I have no idea how to find out. All the reserved words lists I could find online seem to be hopelessly outdated.

This page has a comprehensive list, but it is from 2007:
http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails

There are two wiki entries that seem to deal with reserved words, but one is empty and the other only contains a dead link:
http://wiki.rubyonrails.org/rails/pages/ReservedWords (has dead link)
http://wiki.rubyonrails.org/rails/pages/MagicFieldNames (is empty)

I could find no mention of reserved column names in the Rails Guides as well.

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 28, 2012

Contributor

@marceldegraaf Is this still an issue?

Contributor

isaacsanders commented Apr 28, 2012

@marceldegraaf Is this still an issue?

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva Apr 28, 2012

Member

@marceldegraaf hey, can you provide a patch for this? That'd be awesome, and if you need any help, just let us know. Thanks!

@marceldegraaf hey, can you provide a patch for this? That'd be awesome, and if you need any help, just let us know. Thanks!

@marceldegraaf

This comment has been minimized.

Show comment Hide comment
@marceldegraaf

marceldegraaf Apr 29, 2012

I may have time for that in a week or two. Is that okay?

On Sun, Apr 29, 2012 at 12:16 AM, Carlos Antonio da Silva <
reply@reply.github.com

wrote:

@marceldegraaf hey, can you provide a patch for this? That'd be awesome,
and if you need any help, just let us know. Thanks!


Reply to this email directly or view it on GitHub:
#2629 (comment)

I may have time for that in a week or two. Is that okay?

On Sun, Apr 29, 2012 at 12:16 AM, Carlos Antonio da Silva <
reply@reply.github.com

wrote:

@marceldegraaf hey, can you provide a patch for this? That'd be awesome,
and if you need any help, just let us know. Thanks!


Reply to this email directly or view it on GitHub:
#2629 (comment)

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 29, 2012

Contributor

Oh yah! I am just helping triage things for the Rails core team. Thanks!

Contributor

isaacsanders commented Apr 29, 2012

Oh yah! I am just helping triage things for the Rails core team. Thanks!

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva Apr 29, 2012

Member

@marceldegraaf sounds good, I'll leave the issue open for now and will revisit in a couple weeks. Thanks.

@marceldegraaf sounds good, I'll leave the issue open for now and will revisit in a couple weeks. Thanks.

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 12, 2012

Member

Just more info: I just tested with Rails 3 and was able to run the generator and migrate the database, but not instantiate / create a record:

>> HashTest.create! :name => 'fuu', :hash => 'yeah!'
ActiveRecord::DangerousAttributeError: hash is defined by ActiveRecord
    from .../gems/activerecord-3.2.3/lib/active_record/attribute_methods.rb:90:in `instance_method_already_implemented?'

Hash method is reimplemented in AR

Just more info: I just tested with Rails 3 and was able to run the generator and migrate the database, but not instantiate / create a record:

>> HashTest.create! :name => 'fuu', :hash => 'yeah!'
ActiveRecord::DangerousAttributeError: hash is defined by ActiveRecord
    from .../gems/activerecord-3.2.3/lib/active_record/attribute_methods.rb:90:in `instance_method_already_implemented?'

Hash method is reimplemented in AR

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva Aug 21, 2012

Member

I'm closing this as stale. Please, use the Ruby on Rails Core mailing list to ask for feedback about new features or changes in Rails, or try to create a pull request so people can review the feature with real code. You can also use the Ruby on Rails Talk mailing list for general questions and doubts about the framework. Thanks.

I'm closing this as stale. Please, use the Ruby on Rails Core mailing list to ask for feedback about new features or changes in Rails, or try to create a pull request so people can review the feature with real code. You can also use the Ruby on Rails Talk mailing list for general questions and doubts about the framework. Thanks.

@Fire-Dragon-DoL

This comment has been minimized.

Show comment Hide comment
@Fire-Dragon-DoL

Fire-Dragon-DoL Oct 15, 2012

Contributor

I named a column "length" (quite common) and created me a lot of troubles... I had to rename it

Contributor

Fire-Dragon-DoL commented Oct 15, 2012

I named a column "length" (quite common) and created me a lot of troubles... I had to rename it

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