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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1337376891-20171-180"
Content-Length: 0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 499
Download (untitled) / with headers
text/plain 499b
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
MIME-Version: 1.0
Content-Type: application/octet-stream; name="DBIx-Class-0.08196.patch"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="DBIx-Class-0.08196.patch"
Content-Transfer-Encoding: base64
Content-Length: 794
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}; }
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-3632-1346347798-1741.77292-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 716
Download (untitled) / with headers
text/plain 716b
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!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.