This project is archived and is in readonly mode.
to_xml generates invalid xml with namespaced ActiveRecord
-
CancelProfileIsBroken
- Tag changed from activerecord, module, namespace, serialize, to_xml, xml to activerecord, bugmash, module, namespace, serialize, to_xml, xml
-
Abhishek Parolkar
passes test , with warning
Warning: /test/cases/../../lib/active_record/serializers/xml_serializer.rb:323: warning: Object#type is deprecated; use Object#class
-
Rizwan Reza
verified
+1 This patch only works in 2-3-stable. All tests pass with the warning pasted by Abhishek.
-
Elad Meidar
+1 verified, +1 patch applies and tests pass on 2-3-stable with the same warning as Abhishek Parolkar described.
using #class will just return the Column instance (ActiveRecord::ConnectionAdapters::Column), there should be a better way to access that "type" variable.
-
Edd Morgan
Confirmed passing tests on 2-3-stable; I'm also seeing the deprecation warning. Changing the offending call from Object#type to Object#class causes tests to fail. The two calls don't seem to be returning the same thing.
-
Josh Nichols
- Tag changed from activerecord, bugmash, module, namespace, serialize, to_xml, xml to activerecord, bugmash, module, namespace, patch, serialize, to_xml, verified, xml
+1 for having valid xml generated, and verified the patch makes things happy.
Attached a patch which gets rid of the Object#type deprecation warnings. This includes bythe's original commit in addition to the warning fix.
The problem was type was being called on NilClass.
-
Josh Nichols
So, it looks like this is fixed to some extent on master. Instead of generating my-application/business/project as the root node, it makes my-application-business-project.
If this is the case, should we backport that behavior to 2-3-stable?
-
Rizwan Reza
verified
+1 The patch applies cleanly to 2-3-stable.
-
Rizwan Reza
I think Josh is right. If the functionality is there in master, we should backport that.
-
Josh Nichols
Attached a patch which backports behavior from master. Note, this produces different xml than the original post described.
In particular, the root node is dasherized, ie my-application-project-business-project, and the association nodes have type attributes, ie type="MyApplication::Project::Developer".
-
Dan Croak
+1 verified Josh's 2723-invalid_namespaced_xml-backport.patch applies cleanly and runs green.
-
Repository
- State changed from new to committed
(from [15fd67e9d8155181695add77c8a7b11d92564391]) Backported XML serialization behavior from master for dealing with root nodes that have modules.
ie,
- the root node is dasherized, such that MyApplication::Business::Project becomes <my-application-project-business-project> - association children nodes have type attributes, such that MyApplication::Business::Developer becomes[#2723 to_xml generates invalid xml with namespaced ActiveRecord state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/15fd67e9d8155181695add77c8a7b1... -
Jeremy Kemper
- Tag changed from activerecord, bugmash, module, namespace, patch, serialize, to_xml, verified, xml to activerecord, module, namespace, patch, serialize, to_xml, verified, xml
- Milestone changed from 2.x to 2.3.4
-
Mark Foster
Gentlemen. Have found that all this work to fix this breaks down when the ActiveRecord is in an array since the active_support/core_ext/array/conversions.rb
to_xml method sets options[root] to the class name so that when root is called in the above patch, it finds a value already set and that value includes the invalid characters when the active record has namespaces.I could propose a patch, but I am not proficient in the open source protocols. One way is to add activerecord checking into the conversions.rb file and use model_name instead of class in setting the root, but I am not sure that is the correct approach. The other is in the xml_serializer.rb check if the options[root] value is the default created in conversions.rb, but that is potentially brittle. If someone could comment on the appropriate approach, I will propose a patch. Thank you.
-
Mark Foster
I created a ticket with a simple patch for this issue at:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets...
