[Catalyst] create_related is failing on second time through loop?

2012-06-19 Thread Tim Anderson
Greetings,

I've been working with 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 <= 1, all is well, but if
the number is >1, 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 = $c->request->params->{'user_role'};  #this is what is desired
   $roles = [ $roles ] if ref ($roles) ne 'ARRAY';

  my $existing_record = $c->model('DB::' .
$package_name)->has_record(\%form_key_vals);

   if (defined ($existing_record)) {

 $existing_record = $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 =>
$form_vals{client_id},
   user_id =>
$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 =>
$new_role });  #first time through works, but fails on second pass
 }

   }

When I set DBIC_TRACE=1, I see the following stack trace:


DBIx::Class::Schema::throw_exception('Portal::Schema=HASH(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::Sybase::Microsoft_SQL_Server::Free...',
'DBI::db=HASH(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=REF(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::Microsoft_SQL_Server::Free...',
'insert', 'DBIx::Class::ResultSource::Table=HASH(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::Sybase::Microsoft_SQL_Server::Free...',
'insert', 'DBIx::Class::ResultSource::Table=HASH(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::Microsoft_SQL_Server::Free...',
'DBIx::Class::ResultSource::Table=HASH(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::Sybase::Microsoft_SQL_Server::Free...',
'DBIx::Class::ResultSource::Table=HASH(0x4943810)', 'HASH(0x4f9b328)')
called at /usr/local/share/perl5/DBIx/Class/Row.pm line 350

DBIx::Class::Row::insert('Portal::Model::DB::PortalUserRole=HASH(0x4fa0790)')
called at /usr/local/share/perl5/DBIx/Class/Relationship/Base.pm line 604

DBIx::Class::Relationship::Base::create_related('Portal::Model::DB::PortalUser=HASH(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=HASH(0x4c14790)',
'Portal=HASH(0x4f7fc98)') called at
/usr/local/share/perl5/Catalyst/Action.pm line 65
Catalyst::Action::execute('Catalyst::Action=HASH(0x4df5890)',
'Portal::Controller::Users=HASH(0x4c14790)', 'Portal=HASH(0x4f7fc98)')
called at /usr/local/sha

Re: [Catalyst] create_related is failing on second time through loop?

2012-06-19 Thread Robert Wohlfarth
On Tue, Jun 19, 2012 at 11:20 AM, Tim Anderson  wrote:

> Greetings,
>  foreach my $new_role (@{$roles}) {
>$c->log->debug("Creating new role: " . Dumper($new_role));
>
>$existing_record->create_related ('portal_user_roles', { role_id =>
> $new_role });  #first time through works, but fails on second pass
>

[snip]


> When I set DBIC_TRACE=1, I see the following stack trace:
>
>
> DBIx::Class::Schema::throw_exception('Portal::Schema=HASH(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::Sybase::Microsoft_SQL_Server::Free...',
> 'DBI::db=HASH(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
>

I see that you send $new_role to the log. What is the value when it
crashes? An invalid value may cause unhelpful errors.

-- 
Robert Wohlfarth
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] create_related is failing on second time through loop?

2012-06-19 Thread Len Jaffe
On Tue, Jun 19, 2012 at 2:22 PM, Robert Wohlfarth wrote:

> On Tue, Jun 19, 2012 at 11:20 AM, Tim Anderson  wrote:
>
>>
>>
> I see that you send $new_role to the log. What is the value when it
> crashes? An invalid value may cause unhelpful errors.
>
>
Nice catch.


-- 
lenja...@jaffesystems.com   614-404-4214 www.volunteerable.net
Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
Greenbar : Grubmaster: 2012-2009, Grub
Asst: 2008, Trained: 2007.
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] create_related is failing on second time through loop?

2012-06-19 Thread Tim Anderson
Thanks for your response Robert.

The value when it crashes is valid.  In the case of the example I posted,
two roles were being inserted: 1 and 20.  This is the log text:

[debug] Creating new role: $VAR1 = '1';
[debug] Creating new role: $VAR1 = '20';


The '1' record made it into the database, and the failure came on '20'.  I
can successfully add '20' by itself, so I know it's not a referential
integrity issue (or some such thing).

-Tim


On Tue, Jun 19, 2012 at 1:22 PM, Robert Wohlfarth wrote:
>
>
> I see that you send $new_role to the log. What is the value when it
> crashes? An invalid value may cause unhelpful errors.
>
> --
> Robert Wohlfarth
>
>
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/