Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 77292
Status: open
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: thaljef [...] cpan.org
Cc:
AdminCc:

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



Subject: Use defined() to check for Result object existance
If a Result object has overloaded the "" operators (stringification) with fallback, then evaluating it in boolean context may cause the overload method to fire unnecessarily. And that method could actually return a false value, even though the object does exist. Using the defined() operator prevents this. I've attached a patch that addresses the one incident that I've found so far. There may be others, and I'll submit more patches if I stumble into them. Thanks for the great work! -Jeff
Subject: DBIx-Class-0.08196.patch
diff -Naur DBIx-Class-0.08196/lib/DBIx/Class/Row.pm DBIx-Class-0.08196.mine/lib/DBIx/Class/Row.pm --- DBIx-Class-0.08196/lib/DBIx/Class/Row.pm 2011-11-28 21:15:48.000000000 -0800 +++ DBIx-Class-0.08196.mine/lib/DBIx/Class/Row.pm 2012-05-18 14:18:13.000000000 -0700 @@ -315,10 +315,10 @@ my $existing; # if there are no keys - nothing to search for - if (keys %$them and $existing = $self->result_source + if (keys %$them and defined ($existing = $self->result_source ->related_source($relname) ->resultset - ->find($them) + ->find($them)) ) { %{$rel_obj} = %{$existing}; }
On Fri May 18 17:34:51 2012, THALJEF wrote: Show quoted text
> If a Result object has overloaded the "" operators (stringification) > with fallback, then evaluating it in boolean context may cause the > overload method to fire unnecessarily. And that method could actually > return a false value, even though the object does exist. Using the > defined() operator prevents this. > > I've attached a patch that addresses the one incident that I've found so > far. There may be others, and I'll submit more patches if I stumble > into them. >
Could you perhaps attempt to add ''-stringification on a central class in the test schema - for instance DBICTest::Artist, and see what else will break in the general test suite? Cheers!