"Not all elements respond to to_xml"

82 views
Skip to first unread message

David Speake

unread,
Dec 14, 2011, 12:56:09 PM12/14/11
to shopify-api
Has anyone come across this error before?

"Not all elements respond to to_xml"

It's only started happening the past day or so, and I'm really struggling to figure out what it is. There has been no changes to our code at all.

Here's the backtrace:

Not all elements respond to to_xml
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/array/conversions.rb:163:in `to_xml'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/hash/conversions.rb:115:in `to_xml'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/hash/conversions.rb:110:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/hash/conversions.rb:110:in `to_xml'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb:134:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb:134:in `_nested_structures'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb:58:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/hash/conversions.rb:109:in `__send__'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ext/hash/conversions.rb:109:in `to_xml'
/usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/formats/xml_format.rb:15:in `encode'
/usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/base.rb:976:in `encode'
/usr/lib/ruby/gems/1.8/gems/shopify_api-1.2.5/lib/shopify_api.rb:271:in `only_id'
/usr/lib/ruby/gems/1.8/gems/shopify_api-1.2.5/lib/shopify_api.rb:256:in `open'

Dave

unread,
Dec 14, 2011, 1:10:08 PM12/14/11
to shopify-api
I would upgrade your gem to the latest for one... after that.. put in
some exception handlers and try and isolate where you are sending an
object that should have a to_xml method but doesn't.


On Dec 14, 12:56 pm, David Speake <da...@verycleverstuff.co.uk> wrote:
> Has anyone come across this error before?
>
> "Not all elements respond to to_xml"
>
> It's only started happening the past day or so, and I'm really struggling to figure out what it is. There has been no changes to our code at all.
>
> Here's the backtrace:
>
> Not all elements respond to to_xml
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/array/conversions.rb:163:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:115:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:110:in `each'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:110:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:134:in `call'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:134:in `_nested_structures'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:58:in `method_missing'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:109:in `__send__'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:109:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/forma ts/xml_format.rb:15:in `encode'

> /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/base. rb:976:in `encode'

David Speake

unread,
Dec 14, 2011, 1:16:52 PM12/14/11
to shopi...@googlegroups.com
Hmm. That's a tricky one as we haven't gone through the mammoth task of upgrading to Rails 3 so I'm already at the newest version I can go to.

I can't help but think something has changed on Shopify's end, as I've checked the database integrity, and all seems to be fine there.

I'll persevere for now and see if there's any new developments.

Maybe a silly question, but how can I print/interrogate the object to see what the data is? I'd do something like var_dump or print_r in PHP but never found a way to do it in Rails.

Aaron McLeod

unread,
Dec 14, 2011, 1:20:53 PM12/14/11
to shopi...@googlegroups.com
Can use the ruby debugger, and inspect the object using the p command.
Like so:

def index
  @products = ShopfiyAPI::Product.all
  require 'ruby-debug'; debugger
end

In terminal:

p @products

-- 
Aaron McLeod
http://agmprojects.com

Dave

unread,
Dec 14, 2011, 4:57:30 PM12/14/11
to shopify-api
Also, you can run your App code using Pry, as that gem gives you full
object introspection capabilities far beyond anything PHP world has.

If you were not aware of it, any Ruby object comes with an inspect
method too, allowing you far more control over seeing what makes an
object tick than the primitive PHP var_dump and print_r, commands that
were relegated to the backwaters 5 years ago or more :)

On Dec 14, 1:20 pm, Aaron McLeod <sircoolgu...@gmail.com> wrote:
> Can use the ruby debugger, and inspect the object using the p command.
> Like so:
>
> def index
>   @products = ShopfiyAPI::Product.all
>   require 'ruby-debug'; debugger
> end
>
> In terminal:
>
> p @products
>
> --

> Aaron McLeodhttp://agmprojects.com


>
>
>
>
>
>
>
> On Wednesday, 14 December, 2011 at 1:16 PM, David Speake wrote:
> > Hmm. That's a tricky one as we haven't gone through the mammoth task of upgrading to Rails 3 so I'm already at the newest version I can go to.
>
> > I can't help but think something has changed on Shopify's end, as I've checked the database integrity, and all seems to be fine there.
>
> > I'll persevere for now and see if there's any new developments.
>
> > Maybe a silly question, but how can I print/interrogate the object to see what the data is? I'd do something like var_dump or print_r in PHP but never found a way to do it in Rails.
>
> > On 14 Dec 2011, at 18:10, Dave wrote:
>
> > > I would upgrade your gem to the latest for one... after that.. put in
> > > some exception handlers and try and isolate where you are sending an
> > > object that should have a to_xml method but doesn't.
>

Mike Larkin

unread,
Dec 15, 2011, 9:06:31 AM12/15/11
to shopify-api
I talked to Shopify support, and they said they started including
discount codes in the XML, so my bet is that's what's new and not XML-
friendly.

On Dec 14, 12:56 pm, David Speake <da...@verycleverstuff.co.uk> wrote:
> Has anyone come across this error before?
>
> "Not all elements respond to to_xml"
>
> It's only started happening the past day or so, and I'm really struggling to figure out what it is. There has been no changes to our code at all.
>
> Here's the backtrace:
>
> Not all elements respond to to_xml

> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/array/conversions.rb:163:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:115:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:110:in `each'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:110:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:134:in `call'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:134:in `_nested_structures'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/vendor/ builder-2.1.2/builder/xmlbase.rb:58:in `method_missing'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:109:in `__send__'
> /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.12/lib/active_support/core_ex t/hash/conversions.rb:109:in `to_xml'
> /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/forma ts/xml_format.rb:15:in `encode'

> /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.12/lib/active_resource/base. rb:976:in `encode'

David Speake

unread,
Dec 15, 2011, 9:39:10 AM12/15/11
to shopi...@googlegroups.com
Mike, you're a star! That's exactly what it is!

I'm not sure why it would break things though, as my code should ignore any new elements. I'll add a migration though and that should clear things up.

Thanks again,

Dave

David Speake

unread,
Dec 15, 2011, 10:10:15 AM12/15/11
to shopi...@googlegroups.com
This actually isn't possible, as it is a ShopifyAPI::Order object that triggers this.

In other words, this piece of code fails:

o = ShopifyAPI::Order.find(12345)
o.to_xml
RuntimeError: Not all elements respond to to_xml

Looking at the object data, could it be because the discount code is not an object? For example, each element held in ShippingLines has the type ShippingLine, but rather than each element in DiscountCodes being of the type DiscountCode, it is just a text array.

In which case, this is a Shopify bug?

Is it possible to remove an element like the remove() function in Nokogiri? That way, I can patch my code for the time being.

Edward Ocampo-Gooding

unread,
Dec 15, 2011, 10:31:03 AM12/15/11
to shopi...@googlegroups.com
Hey folks,

We’re taking a look at this now. Thanks for raising a flag about the issue.

Edward Ocampo-Gooding
Developer Advocate, Shopify

Denis Odorcic

unread,
Dec 15, 2011, 3:51:28 PM12/15/11
to shopi...@googlegroups.com
Hey,

The XML that was being generated was valid, the problem was with how ActiveSupport in rails 2.3.x was handling it. In Rails 3, there are no issues and it knows better than to call to_xml on a String. I've modified the discount-codes XML to be structured as follows instead which should no longer cause any issues with Rails 2.3.x. 

<discount-codes type="array">
  <discount-code>
    <code>TENOFF</code>
  </discount-code>
</discount-codes>

Denis Odorcic
Developer - Shopify

David Speake

unread,
Dec 15, 2011, 4:16:48 PM12/15/11
to shopi...@googlegroups.com
Thanks very much Denis, that's done it a treat. Everything is working fine again now, and my Delayed Jobs are processing too.

I promise we are planning the move to Rails 3, it's just a daunting task with thousands of lines of code!

Thanks again,

Dave
Reply all
Reply to author
Forward
0 new messages