Ticket #42 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

TypeError when using ActiveRecord#to_xml

Reported by: rjspott..@comcast.net Assigned to: somebody
Priority: blocker Milestone:
Component: Views Keywords:
Cc:

Description

code to reproduce

# any model where one of the fields is of type timestamp according to type_cast
me = Person.find(97196)  
puts me.to_xml

error thrown

TypeError: can't modify frozen string
        from /usr/local/lib/ruby/1.8/date/format.rb:105:in `chomp!'
        from /usr/local/lib/ruby/1.8/date/format.rb:105:in `method_missing'
        from /usr/local/lib/ruby/1.8/date/format.rb:963:in `_parse'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_definitions.rb:114:in `string_to_time'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_definitions.rb:61:in `type_cast'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1873:in `read_attribute'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1849:in `method_missing'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:291:in `send'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:291:in `compute_value'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:246:in `initialize'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:159:in `new'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:159:in `serializable_attributes'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:159:in `collect'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:159:in `serializable_attributes'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:168:in `add_attributes'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:231:in `to_s'
        from /usr/local/lib/ruby/gems/1.8/gems/builder-2.1.1/lib/builder/xmlbase.rb:134:in `call'
        from /usr/local/lib/ruby/gems/1.8/gems/builder-2.1.1/lib/builder/xmlbase.rb:134:in `_nested_structures'
        from /usr/local/lib/ruby/gems/1.8/gems/builder-2.1.1/lib/builder/xmlbase.rb:58:in `method_missing'
        from /usr/local/lib/ruby/gems/1.8/gems/builder-2.1.1/lib/builder/xmlbase.rb:31:in `__send__'
        from /usr/local/lib/ruby/gems/1.8/gems/builder-2.1.1/lib/builder/xmlbase.rb:31:in `tag!'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:230:in `to_s'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/xml_serialization.rb:107:in `to_xml'

patch

--- lib/merb/core_ext/merb_symbol.rb	(rev 227)
+++ lib/merb/core_ext/merb_symbol.rb	(working copy)

   
   # faster Symbol#to_s to speed up routing.
   def to_s
-    @str_rep ||= id2name.freeze
+    @str_rep ||= id2name
   end
   
   # ["foo", "bar"].map &:reverse #=> ['oof', 'rab']

my $0.02

I consider this a short term fix. I'll keep looking for a work around because fast routing (what that freeze was for) is a big feature of merb. I need xml representations of my models today so....

Change History

05/02/07 11:36:58 changed by e.@brainspl.at

  • status changed from new to closed.
  • resolution set to fixed.

(In [228]) don't freeze the id2name for Symbol#to_s since ActiveRecord::Base#to_xml cries like a baby ;) closes #42 thanks rjspotter

07/06/07 10:50:40 changed by anonymous

  • cc set to wine.
  • keywords changed from TypeError frozen Date to wine.
  • priority changed from blocker to critical.
  • summary changed from TypeError when using ActiveRecord#to_xml to Wine.
  • milestone set to 0.3.x.

07/08/07 01:51:50 changed by anonymous

  • cc changed from wine to painting.
  • component changed from Views to Routing.
  • summary changed from Wine to wine.
  • priority changed from critical to minor.
  • version set to 0.3.
  • milestone changed from 0.3.x to The Future.

07/11/07 07:20:49 changed by anonymous

  • component changed from Routing to Controlling.
  • summary changed from wine to game.
  • priority changed from minor to blocker.
  • version deleted.
  • keywords changed from wine to game.
  • type changed from defect to enhancement.

07/12/07 01:08:08 changed by anonymous

  • priority changed from blocker to critical.
  • component changed from Controlling to Merb.
  • milestone changed from The Future to 0.4.

07/16/07 13:23:57 changed by j..@luretanker.no

  • cc deleted.
  • component changed from Merb to Views.
  • summary changed from game to TypeError when using ActiveRecord#to_xml.
  • priority changed from critical to blocker.
  • milestone deleted.
  • keywords deleted.
  • type changed from enhancement to defect.