Skip Menu |
 

This queue is for tickets about the DBIx-Class-Fixtures CPAN distribution.

Report information
The Basics
Id: 106505
Status: new
Priority: 0/
Queue: DBIx-Class-Fixtures

People
Owner: Nobody in particular
Requestors: frankschwach [...] yahoo.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.001032
Fixed in: (no value)

Attachments
DBIx-Class-Fixtures-fix-result-subclasses.patch



Subject: [PATCH] fix population when using Result subclasses
Download (untitled) / with headers
text/plain 1.3k
Using subclasses of Result classes (e.g. with DBIx-Class-DynamicSubclass) causes an error when populating the schema with a fixture because the same result source directory is read multiple times. For example, following http://search.cpan.org/~syber/DBIx-Class-DynamicSubclass-0.03/lib/DBIx/Class/DynamicSubclass.pm, you would have the Following Result classes: My::Schema::Game My::Schema::Game::Online My::Schema::Game::Shareware My::Schema::Game::PDA DBIx::Class::Fixtures::populate iterates over all source names and then obtains the source directory like this (line 1362): my $source_dir = io->catdir($tmp_fixture_dir, $self->_name_for_source($rs->result_source)); but the _name for source will be "games" for all of the above Result subclasses, hence the fixtures in the games directory will be loaded 4 times and DBIC will throw an error due to a duplicate primary key entry. The attached patch simply keeps track of the source directories seen already and skips if it has been seen and processed previously. For some reason, the same error does NOT occur using the populate command with the dbic-migration command line utility, although I would have thought that that actually uses the same populate method in DBIx::Class::Fixtures but I haven't looked into that more closely. I can provide some code for unit tests too if you need me to. Thanks for all your work on this module!
Subject: DBIx-Class-Fixtures-fix-result-subclasses.patch
--- /software/team131/lib/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/DBIx/Class/Fixtures.pm 2015-08-18 11:32:55.205905000 +0100 +++ /nfs/users/nfs_f/fs5/tmp/Fixtures.pm 2015-08-18 11:32:48.439623000 +0100 @@ -1356,11 +1356,12 @@ my @sorted_source_names = $self->_get_sorted_sources( $schema ); $schema->storage->txn_do(sub { $schema->storage->with_deferred_fk_checks(sub { + my %seen_source_dirs; foreach my $source (@sorted_source_names) { $self->msg("- adding " . $source); my $rs = $schema->resultset($source); my $source_dir = io->catdir($tmp_fixture_dir, $self->_name_for_source($rs->result_source)); - next unless (-e "$source_dir"); + next if ! -e "$source_dir" or ++$seen_source_dirs{$source_dir} > 1 ; my @rows; while (my $file = $source_dir->next) { next unless ($file =~ /\.fix$/);


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.