Skip Menu |

This queue is for tickets about the SimpleDB-Client CPAN distribution.

Report information
The Basics
Id: 63447
Status: resolved
Priority: 0/
Queue: SimpleDB-Client

People
Owner: Nobody in particular
Requestors: chadh [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Attribute values set to empty string are returned as 1
Date: Mon, 29 Nov 2010 16:16:00 -0330
To: bug-SimpleDB-Client [...] rt.cpan.org
From: Chad House <chadh [...] pobox.com>
Minimal test-case (using SimpleDB::Client 1.0402 with perl v5.8.8 on Ubuntu 8.04 LTS): # ============================================ use SimpleDB::Client; use Data::Dumper; my $sdb = SimpleDB::Client->new( secret_key => '...', access_key => '...' ); my $dn = 'testing'; my $id = 'test'; my $rv1 = $sdb->send_request('PutAttributes', { DomainName => $dn, ItemName => $id, 'Attribute.1.Name' => 'foo', 'Attribute.1.Value' => '', 'Attribute.1.Replace' => 'true', }); my $rv2 = $sdb->send_request('GetAttributes', { DomainName => $dn, ItemName => $id, }); print Dumper($rv2); # gives... # 'GetAttributesResult' => { # 'Attribute' => { # 'Value' => 1, # 'Name' => 'foo' # } # }, # ============================================ This seems to be a byproduct of the switch the XML::Bare. Whereas XML::Simple::XMLin parses <A><B/></A> as: $HASH1 = { B => {} }; XML::Bare::xmlin yields: $HASH1 = { B => 1 }; and the XML response fragment from Amazon for blank attributes is indeed something like: <Attribute> <Name>foo</Name> <Value/> </Attribute> so 'Value' becomes 1. (Whether XML::Bare's behaviour is intuitive in this example, is another matter...) Regards, Chad
I'm not sure what to do to fix this bug. I'm not even sure this is a bug, or if it is, whether it is my bug. I'm not one to pass the buck, but in this case I don't see a problem doing it. It seems to me that this would be a problem with XML::Bare if we want to define this as a problem. XML::Bare is returning data where there is none, so I think you should file a bug with them if you want this behavior changed. However, I don't think it should be a problem. Amazon recommends not storing null values, and especially not searching on null values. So perhaps this is a business logic problem. Don't store nulls. The only thing I could do would be to switch back to XML::Simple, which I'm not too keen on doing. Though I'd take a patch if you wanted to do it.
Subject: Re: [rt.cpan.org #63447] Attribute values set to empty string are returned as 1
Date: Thu, 9 Dec 2010 23:05:10 -0330
To: bug-SimpleDB-Client [...] rt.cpan.org
From: Chad House <chadh [...] pobox.com>
On Thu, Dec 9, 2010 at 9:54 PM, JT Smith via RT <bug-SimpleDB-Client@rt.cpan.org> wrote: [...] Show quoted text
> I'm not one to pass the buck, but in this case I don't see a problem > doing it. It seems to me that this would be a problem with XML::Bare > if we want to define this as a problem. XML::Bare is returning > data where there is none, so I think you should file a bug with > them if you want this behavior changed.
I'd considered that, and I agree that XML::Bare is doing something unintuitive, or at least different from XML::Simple which it's claiming to mimic with that routine. I'm not sure if others have come to rely on that behaviour, though, or for that matter if there's much appetite for maintaining XML::Bare itself. To put it in context, I'd actually encountered the issue while fiddling with SimpleDB::Class. There, an item with a string attribute (i.e., isa 'Str') which is not assigned a value (or is explicitly set to undef) gets coerced into the empty string. The memcached layer preserves this (so you might not notice immediately) but ultimately when the object is reconstituted after being fetched back from Amazon, it now has a value of 1 -- which is probably not what you'd expect. Show quoted text
> However, I don't think it should be a problem. Amazon recommends > not storing null values, and especially not searching on null values.
Fair enough, and I expect their advice would be if you don't have a value for something, don't set that property at all on the item concerned -- but that's not how SimpleDB::Class works, and it might be a bit tangly to implement. Show quoted text
> The only thing I could do would be to switch back to XML::Simple, > which I'm not too keen on doing.
Me either ;) Show quoted text
> Though I'd take a patch if you wanted to do it.
How about a patch to use XML::Fast (allegedly faster and more robust than XML::Bare) instead? You'll need the latest (0.10) version, which fixes a bug in the handling of empty element tags (identified by me in the course of investigating this). Not comprehensively tested (yet), but passes the unit test suite in my app when substituted for the original SimpleDB::Client. Attached. Cheers, Chad

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #63447] Attribute values set to empty string are returned as 1
Date: Thu, 9 Dec 2010 22:05:49 -0600
To: bug-SimpleDB-Client [...] rt.cpan.org
From: JT Smith <jt [...] plainblack.com>
Awesome. I'll implement this weekend. On Dec 9, 2010, at 8:35 PM, chadh@pobox.com via RT wrote: Show quoted text
> Queue: SimpleDB-Client > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=63447 > > > On Thu, Dec 9, 2010 at 9:54 PM, JT Smith via RT > <bug-SimpleDB-Client@rt.cpan.org> wrote: > [...]
>> I'm not one to pass the buck, but in this case I don't see a problem >> doing it. It seems to me that this would be a problem with XML::Bare >> if we want to define this as a problem. XML::Bare is returning >> data where there is none, so I think you should file a bug with >> them if you want this behavior changed.
> > I'd considered that, and I agree that XML::Bare is doing something > unintuitive, or at least different from XML::Simple which it's > claiming to mimic with that routine. I'm not sure if others have come > to rely on that behaviour, though, or for that matter if there's much > appetite for maintaining XML::Bare itself. > > To put it in context, I'd actually encountered the issue while > fiddling with SimpleDB::Class. There, an item with a string attribute > (i.e., isa 'Str') which is not assigned a value (or is explicitly set > to undef) gets coerced into the empty string. The memcached layer > preserves this (so you might not notice immediately) but ultimately > when the object is reconstituted after being fetched back from Amazon, > it now has a value of 1 -- which is probably not what you'd expect. >
>> However, I don't think it should be a problem. Amazon recommends >> not storing null values, and especially not searching on null values.
> > Fair enough, and I expect their advice would be if you don't have a > value for something, don't set that property at all on the item > concerned -- but that's not how SimpleDB::Class works, and it might be > a bit tangly to implement. >
>> The only thing I could do would be to switch back to XML::Simple, >> which I'm not too keen on doing.
> > Me either ;) >
>> Though I'd take a patch if you wanted to do it.
> > How about a patch to use XML::Fast (allegedly faster and more robust > than XML::Bare) instead? You'll need the latest (0.10) version, which > fixes a bug in the handling of empty element tags (identified by me in > the course of investigating this). Not comprehensively tested (yet), > but passes the unit test suite in my app when substituted for the > original SimpleDB::Client. Attached. > > Cheers, > > Chad > > --- /home/chadh/perl5/lib/perl5/SimpleDB/Client.pm 2010-05-04 21:30:58.000000000 -0230 > +++ lib/SimpleDB/Client.pm 2010-12-09 16:29:17.000000000 -0330 > @@ -50,7 +50,7 @@ > > use Moose; > use Digest::SHA qw(hmac_sha256_base64); > -use XML::Bare; > +use XML::Fast; > use LWP::UserAgent; > use HTTP::Request; > use Time::HiRes qw(usleep); > @@ -247,9 +247,10 @@ > > sub handle_response { > my ($self, $response) = @_; > - my $content = eval {XML::Bare::xmlin($response->content)}; > + my $tree = eval { xml2hash($response->content) }; > + my (undef, $content) = each %$tree; # discard root like XMLin > # compatibility with SimpleDB::Class > - if (exists $content->{SelectResult} && $content->{SelectResult} == 1) { > + if (exists $content->{SelectResult} && ! $content->{SelectResult}) { > $content->{SelectResult} = {}; > } > # force an item list into an array
Subject: Re: [rt.cpan.org #63447] Attribute values set to empty string are returned as 1
Date: Wed, 15 Dec 2010 16:41:31 -0600
To: bug-SimpleDB-Client [...] rt.cpan.org
From: JT Smith <jt [...] plainblack.com>
I haven't forgotten about you, just busy. It will be done tomorrow.
changed in 1.0500. uploading to cpan now