[Dbix-class] create_related is failing on second time through loop?

Tim Anderson tja824 at gmail.com
Tue Jun 19 17:22:55 GMT 2012


> Greetings,
>
> I've been working with DBIx::Class/Catalyst for about 2 months, and up
> until yesterday I was feeling pretty good about my proficiency... long way
> to go, though.  I have been doing my development in a VirtualBox VM on my
> workstation and arrived at a point where I wanted to move my application =
to
> it's new home.  I set up the new server, installed the necessary Perl
> modules via CPAN, and copied over my application.  Most of it works.
>
> I have two tables, one with a has_many relationship to the other. My
> application needs to take some posted data, updates a single record in the
> main table, and then deletes and re-adds a variable number of records for
> the 'has many' table.  When the variable number <=3D 1, all is well, but =
if
> the number is >1, the first record gets inserted in the table and then I
> get the following in my server output:
>
> [error] DBIx::Class::Relationship::Base::create_related(): Unknown error:
> execute() returned false, but error flags were not set... at
> /opt/lms/catalyst/Portal/script/../lib/Portal/Controller/Users.pm line 429
>
>
> The code in question:
>
>    #handle user_roles
>    my $roles =3D $c->request->params->{'user_role'};  #this is what is
> desired
>    $roles =3D [ $roles ] if ref ($roles) ne 'ARRAY';
>
>       my $existing_record =3D $c->model('DB::' .
> $package_name)->has_record(\%form_key_vals);
>
>    if (defined ($existing_record)) {
>
>      $existing_record =3D $existing_record->update(\%form_vals);  #this is
> working
>
>      # Delete user's existing roles, then add the new ones
>      $c->model('DB::PortalUserRole')->search({ client_id =3D>
> $form_vals{client_id},
>                                                user_id =3D>
> $form_vals{user_id}, })->delete;  #this is working
>
>      foreach my $new_role (@{$roles}) {
>        $c->log->debug("Creating new role: " . Dumper($new_role));
>
>        $existing_record->create_related ('portal_user_roles', { role_id =
=3D>
> $new_role });  #first time through works, but fails on second pass
>      }
>
>    }
>
> When I set DBIC_TRACE=3D1, I see the following stack trace:
>
>
> DBIx::Class::Schema::throw_exception('Portal::Schema=3DHASH(0x35fd380)',
> 'Unknown error: execute() returned false, but error flags were...') called
> at /usr/local/share/perl5/DBIx/Class/Storage.pm line 111
>
> DBIx::Class::Storage::throw_exception('DBIx::Class::Storage::DBI::Sybase:=
:Microsoft_SQL_Server::Free...',
> 'Unknown error: execute() returned false, but error flags were...') called
> at /usr/local/share/perl5/DBIx/Class/Storage/DBI.pm line 1594
>
> DBIx::Class::Storage::DBI::_dbh_execute('DBIx::Class::Storage::DBI::Sybas=
e::Microsoft_SQL_Server::Free...',
> 'DBI::db=3DHASH(0x51679a0)', 'INSERT INTO PORTAL_USER_ROLE ( client_id,
> role_id, user_id) V...', 'ARRAY(0x4fa0490)', 'ARRAY(0x533ea30)') called at
> /usr/local/share/perl5/DBIx/Class/Storage/DBI.pm line 789
>         DBIx::Class::Storage::DBI::__ANON__() called at
> /usr/local/share/perl5/Try/Tiny.pm line 71
>         eval {...} called at /usr/local/share/perl5/Try/Tiny.pm line 67
>         Try::Tiny::try('CODE(0x533e880)',
> 'Try::Tiny::Catch=3DREF(0x520def8)') called at
> /usr/local/share/perl5/DBIx/Class/Storage/DBI.pm line 800
>         DBIx::Class::Storage::DBI::dbh_do(undef, undef, 'INSERT INTO
> PORTAL_USER_ROLE ( client_id, role_id, user_id) V...', 'ARRAY(0x4fa0490)',
> 'ARRAY(0x533ea30)') called at
> /usr/local/share/perl5/DBIx/Class/Storage/DBI.pm line 1558
>
> DBIx::Class::Storage::DBI::_execute('DBIx::Class::Storage::DBI::Sybase::M=
icrosoft_SQL_Server::Free...',
> 'insert', 'DBIx::Class::ResultSource::Table=3DHASH(0x4943810)',
> 'HASH(0x534d2d8)', undef) called at
> /usr/local/share/perl5/DBIx/Class/Storage/DBI/MSSQL.pm line 116
>
> DBIx::Class::Storage::DBI::MSSQL::_execute('DBIx::Class::Storage::DBI::Sy=
base::Microsoft_SQL_Server::Free...',
> 'insert', 'DBIx::Class::ResultSource::Table=3DHASH(0x4943810)',
> 'HASH(0x534d2d8)', undef) called at
> /usr/local/share/perl5/DBIx/Class/Storage/DBI.pm line 1671
>
> DBIx::Class::Storage::DBI::insert('DBIx::Class::Storage::DBI::Sybase::Mic=
rosoft_SQL_Server::Free...',
> 'DBIx::Class::ResultSource::Table=3DHASH(0x4943810)', 'HASH(0x4f9b328)')
> called at /usr/local/share/perl5/DBIx/Class/Storage/DBI/MSSQL.pm line 67
>
> DBIx::Class::Storage::DBI::MSSQL::insert('DBIx::Class::Storage::DBI::Syba=
se::Microsoft_SQL_Server::Free...',
> 'DBIx::Class::ResultSource::Table=3DHASH(0x4943810)', 'HASH(0x4f9b328)')
> called at /usr/local/share/perl5/DBIx/Class/Row.pm line 350
>
> DBIx::Class::Row::insert('Portal::Model::DB::PortalUserRole=3DHASH(0x4fa0=
790)')
> called at /usr/local/share/perl5/DBIx/Class/Relationship/Base.pm line 604
>
> DBIx::Class::Relationship::Base::create_related('Portal::Model::DB::Porta=
lUser=3DHASH(0x533ea78)',
> 'portal_user_roles', 'HASH(0x4f9b130)') called at
> /opt/lms/catalyst/Portal/script/../lib/Portal/Controller/Users.pm line 443
>
> Portal::Controller::Users::save('Portal::Controller::Users=3DHASH(0x4c147=
90)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Action.pm line 65
>         Catalyst::Action::execute('Catalyst::Action=3DHASH(0x4df5890)',
> 'Portal::Controller::Users=3DHASH(0x4c14790)', 'Portal=3DHASH(0x4f7fc98)')
> called at /usr/local/share/perl5/Catalyst.pm line 1668
>         eval {...} called at /usr/local/share/perl5/Catalyst.pm line 1668
>         Catalyst::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4df5890)') called=
 at
> /usr/local/share/perl5/Catalyst/Plugin/StackTrace.pm line 94
>         Catalyst::Plugin::StackTrace::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4df5890)') called=
 at
> /usr/local/share/perl5/Catalyst/Action.pm line 60
>         Catalyst::Action::dispatch('Catalyst::Action=3DHASH(0x4df5890)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/ActionChain.pm line 38
>
> Catalyst::ActionChain::dispatch('Catalyst::ActionChain=3DHASH(0x4f83db8)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Controller.pm line 125
>
> Catalyst::Controller::_ACTION('Portal::Controller::Users=3DHASH(0x4c14790=
)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Action.pm line 65
>         Catalyst::Action::execute('Catalyst::Action=3DHASH(0x4dee848)',
> 'Portal::Controller::Users=3DHASH(0x4c14790)', 'Portal=3DHASH(0x4f7fc98)')
> called at /usr/local/share/perl5/Catalyst.pm line 1668
>         eval {...} called at /usr/local/share/perl5/Catalyst.pm line 1668
>         Catalyst::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4dee848)') called=
 at
> /usr/local/share/perl5/Catalyst/Plugin/StackTrace.pm line 94
>         Catalyst::Plugin::StackTrace::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4dee848)') called=
 at
> /usr/local/share/perl5/Catalyst/Action.pm line 60
>         Catalyst::Action::dispatch('Catalyst::Action=3DHASH(0x4dee848)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Dispatcher.pm line 257
>
> Catalyst::Dispatcher::_do_forward('Catalyst::Dispatcher=3DHASH(0x21c9488)=
',
> 'forward', 'Portal=3DHASH(0x4f7fc98)', '_ACTION') called at
> /usr/local/share/perl5/Catalyst/Dispatcher.pm line 237
>
> Catalyst::Dispatcher::forward('Catalyst::Dispatcher=3DHASH(0x21c9488)',
> 'Portal=3DHASH(0x4f7fc98)', '_ACTION') called at
> /usr/local/share/perl5/Catalyst.pm line 358
>         Catalyst::forward('Portal=3DHASH(0x4f7fc98)', '_ACTION') called at
> /usr/local/share/perl5/Catalyst/Controller.pm line 99
>
> Catalyst::Controller::_DISPATCH('Portal::Controller::Users=3DHASH(0x4c147=
90)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Action.pm line 65
>         Catalyst::Action::execute('Catalyst::Action=3DHASH(0x4dee560)',
> 'Portal::Controller::Users=3DHASH(0x4c14790)', 'Portal=3DHASH(0x4f7fc98)')
> called at /usr/local/share/perl5/Catalyst.pm line 1668
>         eval {...} called at /usr/local/share/perl5/Catalyst.pm line 1668
>         Catalyst::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4dee560)') called=
 at
> /usr/local/share/perl5/Catalyst/Plugin/StackTrace.pm line 94
>         Catalyst::Plugin::StackTrace::execute('Portal=3DHASH(0x4f7fc98)',
> 'Portal::Controller::Users', 'Catalyst::Action=3DHASH(0x4dee560)') called=
 at
> /usr/local/share/perl5/Catalyst/Action.pm line 60
>         Catalyst::Action::dispatch('Catalyst::Action=3DHASH(0x4dee560)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Dispatcher.pm line 257
>
> Catalyst::Dispatcher::_do_forward('Catalyst::Dispatcher=3DHASH(0x21c9488)=
',
> 'forward', 'Portal=3DHASH(0x4f7fc98)', '/users/_DISPATCH') called at
> /usr/local/share/perl5/Catalyst/Dispatcher.pm line 237
>
> Catalyst::Dispatcher::forward('Catalyst::Dispatcher=3DHASH(0x21c9488)',
> 'Portal=3DHASH(0x4f7fc98)', '/users/_DISPATCH') called at
> /usr/local/share/perl5/Catalyst.pm line 358
>         Catalyst::forward('Portal=3DHASH(0x4f7fc98)', '/users/_DISPATCH')
> called at /usr/local/share/perl5/Catalyst/Dispatcher.pm line 105
>
> Catalyst::Dispatcher::dispatch('Catalyst::Dispatcher=3DHASH(0x21c9488)',
> 'Portal=3DHASH(0x4f7fc98)') called at /usr/local/share/perl5/Catalyst.pm =
line
> 1614
>         Catalyst::dispatch('Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst/Plugin/Static/Simple.pm line 77
>         Class::MOP::Class:::around('CODE(0x284fba8)',
> 'Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/lib64/perl5/Class/MOP/Method/Wrapped.pm line 162
>         Class::MOP::Method::Wrapped::__ANON__('Portal=3DHASH(0x4f7fc98)')
> called at /usr/local/lib64/perl5/Class/MOP/Method/Wrapped.pm line 91
>         Portal::dispatch('Portal=3DHASH(0x4f7fc98)') called at
> /usr/local/share/perl5/Catalyst.pm line 1964
>         Catalyst::__ANON__() called at /usr/local/share/perl5/Try/Tiny.pm
> line 76
>         eval {...} called at /usr/local/share/perl5/Try/Tiny.pm line 67
>         Try::Tiny::try('CODE(0x4f616a0)',
> 'Try::Tiny::Catch=3DREF(0x4ecac50)') called at
> /usr/local/share/perl5/Catalyst.pm line 1970
>         Catalyst::handle_request('Portal', 'env', 'HASH(0x4f58460)',
> 'response_cb', 'CODE(0x4f61340)') called at
> /usr/local/share/perl5/Catalyst/Engine.pm line 682
>         Catalyst::Engine::__ANON__('CODE(0x4f61340)') called at
> /usr/local/share/perl5/Plack/Handler/FCGI.pm line 137
>         Plack::Handler::FCGI::run('Plack::Handler::FCGI=3DHASH(0x28ff9a0)=
',
> 'CODE(0x49086f8)', 'HASH(0x218b718)') called at
> /usr/local/share/perl5/Catalyst/Engine.pm line 664
>         Catalyst::Engine::run('Catalyst::Engine=3DHASH(0x2e0c958)',
> 'Portal', 'CODE(0x49086f8)', '/opt/lms/catalyst/sockets/portal.socket',
> 'HASH(0x218b718)', 'Plack::Handler::FCGI=3DHASH(0x28ff9a0)') called at
> /usr/local/share/perl5/Catalyst.pm line 2427
>         Catalyst::run('Portal', '/opt/lms/catalyst/sockets/portal.socket',
> 'HASH(0x218b718)', 'Plack::Handler::FCGI=3DHASH(0x28ff9a0)') called at
> /usr/local/share/perl5/Catalyst/ScriptRole.pm line 91
>
> Catalyst::ScriptRole::_run_application('Catalyst::Script::FastCGI=3DHASH(=
0x219e6e8)')
> called at /usr/local/share/perl5/Catalyst/ScriptRole.pm line 61
>
> Catalyst::ScriptRole::run('Catalyst::Script::FastCGI=3DHASH(0x219e6e8)')
> called at /usr/local/share/perl5/Catalyst/ScriptRunner.pm line 50
>         Catalyst::ScriptRunner::run('Catalyst::ScriptRunner', 'Portal',
> 'FastCGI') called at script/portal_fastcgi.pl line 4
>
> I've been Googling for the past day and a half, and I've tried several
> things to isolate the problem and shed more light, but I am at a
> standstill.  Has anyone seen this happen before, to be able to point me
> toward a solution?  I've traced on the database side, and I don't even
> think the second insert is being run there.  I'd greatly appreciate any
> help.
>
> Yes, I realize there are Catalyst dependencies in my code, and I have
> asked the question on that list too.  Unfortunately, I'm not comfortable
> yet decoupling the DBIx modules from the Catalyst framework, but that's my
> next step.
>
> Thanks in advance.
>
>
>
> -Tim
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120619/c77=
9ecce/attachment-0001.htm


More information about the DBIx-Class mailing list