Skip to content

DBI->trace treats class name as hash reference #1340

Description

@fglock

Summary

PerlOnJava cannot call the DBI class method DBI->trace(0). It treats the
class name string ("DBI") as though it were a database-handle hash
reference. This prevents distributions that disable DBI tracing during
initialization from loading at all.

Reproduction

Run either backend:

./jperl -MDBI -e 'DBI->trace(0); print "ok\\n"'
./jperl --interpreter -MDBI -e 'DBI->trace(0); print "ok\\n"'

Expected output:

ok

Actual result on both backends:

Can't use string ("DBI") as a HASH ref while "strict refs" in use at jar:PERL5LIB/DBI.pm line 1355.

The same call succeeds under system Perl with DBI 1.651.

CPAN failure that exposed the bug

The CPAN random-tester run 20260910-101908-8428 reported FAIL for
DBIx::PhraseBook 1.003. Its test file loads DBIx::PhraseBook, whose
INIT block calls:

DBI->trace(0);

The test process aborts before the first assertion, producing zero tests:

t/DBIx-PhraseBook.t (Wstat: 65280) ...
Tests: 0 Failed: 0
Result: FAIL

This is not a DBIx::PhraseBook-specific operation; the minimal DBI
reproducer fails without that distribution and on both PerlOnJava execution
backends.

Technical evidence

The bundled Perl implementation of DBI::trace currently begins with:

sub trace {
    my ($dbh, $level, $output) = @_;
    $level ||= 0;
    $dbh->{TraceLevel} = $level;
    ...
}

For a class-method invocation, $dbh is the string "DBI". Standard DBI
accepts DBI->trace(...) as a package-level tracing operation, so the
implementation needs to distinguish class-level invocation from a
database-handle invocation, or otherwise provide compatible class-method
semantics.

Impact

Any CPAN module that calls DBI->trace(...) during module initialization can
fail to compile or load under PerlOnJava. This also masks the module's own
tests, as demonstrated by DBIx::PhraseBook.

Suggested regression coverage

Add a project-owned test that invokes DBI->trace(0) under both backends and
asserts that it completes without a hash-reference error. Include at least
one class-level trace-setting case and preserve handle-level behavior if the
implementation shares the same method.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions