Help with undefined method error on character

So in my early days of creating this system, I created an attribute called ‘spell_mod’ on the character model, like so:

module AresMUSH
  class Character
    attribute :spell_mod, :type => DataType::Integer, :default => 0
    attribute :has_cast, :type => DataType::Boolean, :default => false
  end
end

I later decided that it made more sense on the combatant and moved it. Now, though, I get a recurring string of errors related to spell_mod (but for some reason never to has_cast, which also moved) any time a character does anything. It creates a small but noticeable lag on game.

For example, sending a message to the chat channel resulted in:

2018-09-18 01:22:26 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x0000000002743838>
Did you mean?  spells_learned
2018-09-18 01:22:26 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00000000025125c8>
Did you mean?  spells_learned
2018-09-18 01:22:26 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00000000023c3e10>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x0000000004f9bc90>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x0000000004f73740>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00000000047e0780>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00000000047bcf60>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00007fbb8c18d3d8>
Did you mean?  spells_learned
2018-09-18 01:22:27 WARN - Model AresMUSH::Character failed to respond to spell_mod undefined method `spell_mod=' for #<AresMUSH::Character:0x00007fbb8c17f788>
Did you mean?  spells_learned

I have no idea what’s causing this or how to fix it. Do you have any insight into how I might track down the root cause of this?

1 Like

Glitch was nice to me and tracked it down tonight - in case anyone else runs into something similar, he said it was bad data in the DB, and that he cleared out the attribute from all of the db data.

That’s a common error if you don’t do the little dance necessary when removing a database field that already has data in it. Here’s what to do:

  1. Put the field back the way it was, but without the DataType stuff. Just make it a regular string.
  2. Do a database query (either using tinker or the ruby command) to set everyone’s value for that field to nil.
  3. Now you can safely remove the field.

For more info on why this happens and some more detailed code examples, see Removing a Database Field.

1 Like

Excellent, thanks. That will be helpful the next time I invariably mess something up.