This project is archived and is in readonly mode.
to_xml doesn't work in such case: Event.select('title as t').to_xml
-
Neeraj Singh
- Tag changed from select, to_xml to ruby19, select, to_xml
Just to add to the ticket it is working fine with ruby 1.8.7. I am getting following output
<?xml version="1.0" encoding="UTF-8"?> <events type="array"> <event> <t type="NilClass">railsconf</t> </event> </events> -
knoopx (at gmail)
I'm having similar problems when including associations.
2) Api::V1::StreamablesController should show details for a movie Failure/Error: get(:show, :id => @movie.id, :format => :xml) undefined method `type' for nil:NilClass # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:230:in `compute_type' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:21:in `initialize' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:74:in `new' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:74:in `block in serializable_attributes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:73:in `each' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:73:in `map' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:73:in `serializable_attributes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:115:in `add_attributes_and_methods' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:102:in `block in serialize' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:31:in `tag!' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:101:in `serialize' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:175:in `to_xml' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:218:in `block (2 levels) in add_associations' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:210:in `each' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:210:in `block in add_associations' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:31:in `tag!' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:209:in `add_associations' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:192:in `block in add_includes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serialization.rb:51:in `block in serializable_add_includes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serialization.rb:40:in `each' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serialization.rb:40:in `serializable_add_includes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:191:in `add_includes' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:186:in `add_extra_behavior' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:103:in `block in serialize' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/builder-2.1.2/lib/builder/xmlbase.rb:31:in `tag!' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.0/lib/active_model/serializers/xml.rb:101:in `serialize' # /Users/knoopx/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serializers/xml_serializer.rb:175:in `to_xml' # ./app/controllers/api/v1/streamables_controller.rb:16:in `block (2 levels) in show' -
knoopx (at gmail)
It's obvious that the problem is caused by this line:
type = @serializable.class.serialized_attributes.has_key?(name) ? super : @serializable.class.columns_hash[name].typeIf somehow, the resulting SQL is using a dynamic column,
@serializable.class.columns_hash[name].typewill fail.
In my case I'm getting the exception when evaling@serializable.class.columns_hash["the_parent_id"].typewhich is not present in the schema due it's a dynamic column.This exception is thrown even if
:skip_typesis set to true. -
knoopx (at gmail)
If it works on 1.8 and not in 1.9 it may be due is inheriting attributes that should not be inherited.
-
José Valim
- State changed from new to open
- Milestone cleared.
- Assigned user set to José Valim
- Importance changed from to Low
knoopx, could you please provide a patch with tests fixing this error?
-
knoopx (at gmail)
This patch makes it behave in ruby-1.9 like using ruby-1.8. I've debugged the attributes on both versions and are exactly the same. when
-
José Valim
The patch needs tests to ensure we won't have regressions.
-
Ryan Bigg
Automatic cleanup of spam.
-
Santiago Pastorino
knoopx are you able to provide a test? can somebody provide a test case for this?.
Thanks. -
Cesario
- Tag set to rails 3.0.0, activecord, serialization, xml
Here's a patch that includes knoopx's one, and the required test.
-
Cesario
I just can't attach any file, that's probably why I kept triggering pull requests instead of discussing the issues here last time... here's my branch on GH https://github.com/cesario/rails/commits/lighthouse-4840
-
Cesario
And here's a gist if you wanna have the patch directly
-
José Valim
- Assigned user changed from José Valim to Aaron Patterson
Cesario, was this applied already?
-
Cesario
Nop, there's a pull request opened as I wanted to clean up a bit my repo https://github.com/rails/rails/pull/115
-
Aaron Patterson
- State changed from incomplete to resolved
@Cesario I've merged in your changes. Thanks!
-
Repository
(from [fe0db2b80588446b34f5f89bbe73f04b88fb06c9]) to_xml doesn't work in such case: Event.select('title as t').to_xml [#4840 to_xml doesn't work in such case: Event.select('title as t').to_xml state:resolved]
NilClass.type is no longer defined in Ruby 1.9 and causes ActiveRecord::Base.to_xml to fail with message: undefined method
type' for nil:NilClass<br/> https://github.com/rails/rails/commit/fe0db2b80588446b34f5f89bbe73f04b88fb06c9
