This situation is dangerous in case the end-user employs something like
DBIx::Class::Helper::ResultSet::IgnoreWantarray
Besides the trivial fix in ::Row::copy, this commit introduces the
DBIC_ASSERT_NO_INTERNAL_WANTARRAY=1 mechanism (which will be
automatically picked up and engaged by our CI due to
eed5492f). As a
bonus the check is usable on DBIC dependencies as well.
SQLite DDL (it is one of the few producers *NOT* quoting by default)
- Back out self-cleaning from DBIx::Class::Carp for the time being
(as a side effect fixes RT#86267)
+ - Fix incorrect internal use of implicit list context in copy()
- Tests no longer fail if $ENV{DBI_DSN} is set
- Throw clearer exception on ->new_related() with a non-existent
relationship.
# otherwise we are good
: 0
,
+
+ ASSERT_NO_INTERNAL_WANTARRAY => $ENV{DBIC_ASSERT_NO_INTERNAL_WANTARRAY} ? 1 : 0,
};
if ($] < 5.009_005) {
use warnings;
use Sub::Name;
use DBIx::Class::Carp;
+use DBIx::Class::_Util 'fail_on_internal_wantarray';
use namespace::clean;
our %_pod_inherit_config =
}
);
} elsif ($acc_type eq 'multi') {
- $meth{$rel} = sub { shift->search_related($rel, @_) };
+ $meth{$rel} = sub {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and wantarray and my $sog = fail_on_internal_wantarray($_[0]);
+ shift->search_related($rel, @_)
+ };
$meth{"${rel}_rs"} = sub { shift->search_related_rs($rel, @_) };
$meth{"add_to_${rel}"} = sub { shift->create_related($rel, @_); };
} else {
use warnings;
use DBIx::Class::Carp;
-use Sub::Name qw/subname/;
-use Scalar::Util qw/blessed/;
-
+use Sub::Name 'subname';
+use Scalar::Util 'blessed';
+use DBIx::Class::_Util 'fail_on_internal_wantarray';
use namespace::clean;
our %_pod_inherit_config =
my $meth_name = join '::', $class, $meth;
*$meth_name = subname $meth_name, sub {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and wantarray and my $sog = fail_on_internal_wantarray($_[0]);
my $self = shift;
my $rs = $self->$rs_meth( @_ );
return (wantarray ? $rs->all : $rs);
use DBIx::Class::Carp;
use DBIx::Class::ResultSetColumn;
use Scalar::Util qw/blessed weaken reftype/;
+use DBIx::Class::_Util 'fail_on_internal_wantarray';
use Try::Tiny;
use Data::Compare (); # no imports!!! guard against insane architecture
my $rs = $self->search_rs( @_ );
if (wantarray) {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray($rs);
return $rs->all;
}
elsif (defined wantarray) {
$attrs->{offset} += $min;
$attrs->{rows} = ($max ? ($max - $min + 1) : 1);
return $self->search(undef, $attrs);
- #my $slice = (ref $self)->new($self->result_source, $attrs);
- #return (wantarray ? $slice->all : $slice);
}
=head2 next
use base 'DBIx::Class';
use DBIx::Class::Carp;
+use DBIx::Class::_Util 'fail_on_internal_wantarray';
use namespace::clean;
# not importing first() as it will clash with our own method
my $cursor = $self->func_rs($function)->cursor;
if( wantarray ) {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray($self);
return map { $_->[ 0 ] } $cursor->all;
}
);
my $copied = $relnames_copied->{ $rel_info->{source} } ||= {};
- foreach my $related ($self->search_related($relname)) {
+ foreach my $related ($self->search_related($relname)->all) {
my $id_str = join("\0", $related->id);
next if $copied->{$id_str};
$copied->{$id_str} = 1;
use constant SPURIOUS_VERSION_CHECK_WARNINGS => ($] < 5.010 ? 1 : 0);
use Carp;
+use Scalar::Util qw(refaddr weaken);
use base 'Exporter';
-our @EXPORT_OK = qw(modver_gt_or_eq);
+our @EXPORT_OK = qw(modver_gt_or_eq fail_on_internal_wantarray);
sub modver_gt_or_eq {
my ($mod, $ver) = @_;
eval { $mod->VERSION($ver) } ? 1 : 0;
}
+{
+ my $list_ctx_ok_stack_marker;
+
+ sub fail_on_internal_wantarray {
+ return if $list_ctx_ok_stack_marker;
+
+ if (! defined wantarray) {
+ croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
+ }
+
+ my $cf = 1;
+ while ( ( (caller($cf+1))[3] || '' ) =~ / :: (?:
+
+ # these are public API parts that alter behavior on wantarray
+ search | search_related | slice | search_literal
+
+ |
+
+ # these are explicitly prefixed, since we only recognize them as valid
+ # escapes when they come from the guts of CDBICompat
+ CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
+
+ ) $/x ) {
+ $cf++;
+ }
+
+ if (
+ (caller($cf))[0] =~ /^(?:DBIx::Class|DBICx::)/
+ ) {
+ my $obj = shift;
+
+ DBIx::Class::Exception->throw( sprintf (
+ "Improper use of %s(0x%x) instance in list context at %s line %d\n\n\tStacktrace starts",
+ ref($obj), refaddr($obj), (caller($cf))[1,2]
+ ), 'with_stacktrace');
+ }
+
+ my $mark = [];
+ weaken ( $list_ctx_ok_stack_marker = $mark );
+ $mark;
+ }
+}
+
1;