From: Michael G Schwern Date: Tue, 11 Mar 2008 01:18:49 +0000 (+0000) Subject: Fixed a heisenbug where looking at a column group would cause it to be shared. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=96eab6f8adc4e23f4212aa6b6bf681137aa5f654;p=dbsrgits%2FDBIx-Class-Historic.git Fixed a heisenbug where looking at a column group would cause it to be shared. --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm index 530aaac..f9dd69d 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm @@ -4,6 +4,8 @@ package # hide from PAUSE use strict; use warnings; +use Storable 'dclone'; + use base qw/DBIx::Class::Row/; __PACKAGE__->mk_classdata('_column_groups' => { }); @@ -29,7 +31,9 @@ sub _add_column_group { sub _register_column_group { my ($class, $group, @cols) = @_; - my $groups = { %{$class->_column_groups} }; + # Must do a complete deep copy else column groups + # might accidentally be shared. + my $groups = dclone $class->_column_groups; if ($group eq 'Primary') { $class->set_primary_key(@cols); diff --git a/t/cdbi-t/early_column_heisenbug.t b/t/cdbi-t/early_column_heisenbug.t new file mode 100644 index 0000000..09ea6d9 --- /dev/null +++ b/t/cdbi-t/early_column_heisenbug.t @@ -0,0 +1,28 @@ +use strict; + +use Test::More; + +BEGIN { + eval "use DBIx::Class::CDBICompat;"; + plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@") + : ('no_plan'); +} + + +{ + package Thing; + use base qw(DBIx::Class::CDBICompat); +} + +{ + package Stuff; + use base qw(DBIx::Class::CDBICompat); +} + +# There was a bug where looking at a column group before any were +# set would cause them to be shared across classes. +is_deeply [Stuff->columns("Essential")], []; +Thing->columns(Essential => qw(foo bar baz)); +is_deeply [Stuff->columns("Essential")], []; + +1;