Search code examples
perldbix-class

randomly seeing 'Stub found while resolving method "???" overloading """" in package "XXX" '


We've in the past few weeks relocated our server and are randomly (but too often) getting the follow error.

The dbix verison is now 0.082820 and previously was 0.08250 without this error occurring.

"Stub found while resolving method "???" overloading """" in package "XXX" at /home/perlbrew/.perlbrew/libs/perl-5.16.3@latest-20160209/lib/perl5/DBIx/Class/Row.pm line 1250."

the package XXX

has which might be related

use Class::Trait qw( TPrintable  );

sub inflate_result {
    my $self = shift;
    my $ret = $self->next::method(@_);
    my $typeCd = $ret->typeCd;
    given ($typeCd) {
        when( $specialTypeCd ) {
            $self->ensure_class_loaded( $specialSubClass );
            bless ($ret, $specialSubClass);
        }
        default {
            bless ($ret, $self);
        }
    }
    return $ret;
}

The code bringing in package XXX has a helper method doing:

my $theY = $c->model('DB::Y')->find( $yID,
    {
        prefetch => [ { 'xxxs' => 'typecd' } , 'zid' ]
    });

return $theY;

thoughts in what the problem is; how to get it consistent to submit a bug report.

We already know about the potential workaround in Abstract.pm of SQLA_ISVALUE_IGNORE_AUTOGENERATED_STRINGIFICATION=1


Solution

  • A suggested fix by a person who choices to remain anonymous (which was not enough for us in our perl 5.16.3)

    We ended up switching to perl 5.26 and the problem is gone. (We were told "You are very unlikely to: 5.18 overhauled a lot of the overload internals.")

    diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm
    index 264b0b1..b4d8fb4 100644
    --- a/lib/SQL/Abstract.pm
    +++ b/lib/SQL/Abstract.pm
    @@ -104,7 +104,11 @@ sub is_plain_value ($) {
             # "%s"> and the source of overload::mycan())
             #
             # either has stringification which DBI SHOULD prefer out of the box
    -        grep { *{ (qq[${_}::(""]) }{CODE} } @{ $_[2] = mro::get_linear_isa( $_[1] ) }
    +        grep {
    +          *{ (qq[${_}::()]) }{CODE}
    +            and
    +          *{ (qq[${_}::(""]) }{CODE}
    +        } @{ $_[2] = mro::get_linear_isa( $_[1] ) }
               or
             # has nummification or boolification, AND fallback is *not* disabled
             (
    

    To put your mind at ease: here is what is actually happening:

    perl -e '
    
        use warnings;
        use strict;
    
        require Scalar::Util;
    
        {
          package Some::Overload;
          use overload
            q{""}       => "named_stringifier",
            fallback => 1,
          ;
    
          sub named_stringifier { $_[0] . "" }
        }
    
        {
          package Some::Subclass;
          use base "Some::Overload";
        }
    
    
        my $thing = bless {}, "Some::Subclass"; 
    
    
        {
          no strict "refs";
          grep { *{ (qq[${_}::(""]) }{CODE} } qw( Some::Subclass Some::Overload );
        }
    
    
        for (1, 2) {
    
    
          # simulates runtime require of some *UNRELATED* class
          eval sprintf <<EOS, $_;
          {
            package Some::UnrelatedThing%s;
            use overload
              q{""} => sub { \$_[0] . "" },
              fallback => 1,
            ;
          }
    EOS
    
          my $some_object = bless {}, "Some::Subclass";
        }
    
        warn "got here, all is well\n";
        exit 0;
    '