Back to this issue, sorry, been in HI for 2 weeks :)

OK, here's some small(er) code I that repeats the problem. To recap, the gist is, i'm adding an item (a "system") to a customer, and post insert, the new item only shows up on certain page reloads - certain children aren't seeing the newly inserted item. the new item info web page/data calls the update() fxn...

sub update {
    my $self = shift;
    my $cid = shift;
    my %params = $self->model->fdat;
    $params{
'cid'} = $cid;
    my (@toupdate, @created);

# SNIPPED OTHER UPDATE CODE, WHAT'S REALLY BREAKING FOLLOWS #

    $self->model->log(
'info', "START updating $cid");

   
# new system
    if ($params{'addsystem'}) {
        my %tmp = %params;
        $tmp{
'cid_new'} = $cid;
        my ($cd, $tu) = new_system($self, \%tmp);
        push @toupdate, @$tu;
        push @created, @$cd;
    }
# end new system

# SNIP #

    # process updates
    foreach my $obj (@toupdate) {
        $self->model->log(
'info', "updating obj:");
        $self->model->log_dumper(
'info', $obj);
        eval { $obj->update };
        if ($@) {
            $self->model->log(
'info', 'update failed, rolling back');
            foreach my $o (@created) { $o->dbi_rollback; }
            $self->context->throw(
'update', $@ );
        } else {
            push @created, $obj;
        }
    }

   
# if we made it this far, commit everything
    foreach my $obj (@toupdate) { $obj->dbi_commit; }
    foreach my $obj (@created) { $obj->dbi_commit; }
   
    return;
}

sub new_system {
    my $self = shift;
    my $params = shift;
    my $systems_profile = Lib::Profiles->system;
    my $sys;
    my (@created, @toupdate);
   
# reassign params from form names
    my %tmp = map { $_ => $$params{"${_}_new"} } Lib::Systems->columns;
    my ($data, $errors) = $self->model->validate($systems_profile, \%tmp);
    if (@$errors) {
        $self->context->throw(
'required', { fields => [EMAIL PROTECTED] } );
    } else {
        my %clean_args;
        $self->model->log(
'info', "inserting new system");
        while (my($key, $value) = each %$data) {
            next unless ( Lib::Systems->find_column( $key ) );
            $clean_args{$key} = $value;
        }
# end while
        eval { $sys = Lib::Systems->create( \%clean_args ) };
        if ($@) { $self->context->throw(
'create', $@ ); }
        push @created, $sys;

        if ($$params{
'ip_new_new'}) {
            my $assign_date = $self->model->{
'time'}->ymd;
            push @toupdate, update_ip($self, $sys->sysid, $$params{
'cid_new'}, $assign_date, 0, split /[\s\,]/, $$params{'ip_new_new'});
            $self->model->set(
'ip_new_new','');
        }
# end new ip if
        return [EMAIL PROTECTED], [EMAIL PROTECTED];
    }
}

sub update_ip {
    my $self = shift;
    my $sysid = shift;
    my $cid = shift;
    my $assign_date = shift;
    my $relen_date = shift;
    my @ips = @_;
    my @out;

    my $ipmap_profile = Lib::Profiles->ip;
    foreach my $ip (@ips) {
        my $ipobj = Lib::Ipmap->retrieve($ip);
       
# throw a warning if this IP is in use
        if ($ipobj->status && $ipobj->sysid != $sysid) {
            $self->model->log(
'info', "$ip is already assigned to sysid ".$ipobj->sysid);
            push my @$errors,
"$ip is already assigned to <a href="">.$ipobj->cid.'>'.$ipobj->cid.'</a>';
            $self->context->throw(
'required', { fields => [EMAIL PROTECTED] } );
        }
       
# reassign params from form names
        my %tmp;
        $tmp{
'ip'} = $ip;
        $tmp{
'cid'} = $cid;
        $tmp{
'sysid'} = $sysid;
        if (defined $relen_date) {
            $tmp{
'relen_date'} = $relen_date;
            if ($tmp{
'relen_date'} == 0) { undef $tmp{'relen_date'}; }
        }
        else { $tmp{
'relen_date'} = $ipobj->relen_date; }
        if (defined $assign_date) { $tmp{
'assign_date'} = $assign_date; }
        else { $tmp{
'assign_date'} = $ipobj->assign_date; }
        $tmp{
'status'} = 1;
        if ($tmp{
'relen_date'}) { $tmp{'status'} = 0; }
       
        my ($data, $errors) = $self->model->validate($ipmap_profile, \%tmp);
        if (@$errors) {
            $self->context->throw(
'required', { fields => [EMAIL PROTECTED] } );
        } else {
            $self->model->log(
'info', "updating values for $ip");
            while (my($key, $value) = each %$data) {
                next unless ( Lib::Ipmap->find_column( $key ) );
                $self->model->log(
'info', "setting $key to $value" );
                eval { $ipobj->$key( $value ) };
                if ($@) { $self->context->throw(
'set value', $@ ); }
            }
# end while
            push @out, $ipobj;
        }
# end add ip else
    } # end add ip foreach
    return @out;
}

In the logs:

94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 44 START updating col00129
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 324 inserting new system
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 411 updating values for 69.55.230.156
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 417 setting cid to col00129
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 417 setting status to 1
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 417 setting assign_date to 2004-05-17
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 417 setting sysid to 1039
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 417 setting relen_date to
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 219 updating obj:
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220 $VAR1 = bless( {
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'cid' => 'col00129',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'assign_date' => '2004
-05-17',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'status' => 1,
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'ip' => '69.55.230.156
',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'sysid' => '1039',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  'relen_date' => undef,
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                  '__Changed' => {
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                   'assi
gn_date' => '1',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                   'stat
us' => '1',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                   'cid' => '1',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                   'relen_date' => '1',
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                   'sysid' => '1'
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                                 }
94478 2004-05-17/15:42:28 64.186.244.42 info dave Plugin::Customers 220                }, 'Lib::Ipmap' );

(Now loading the page that shows the newly added item)

94478 2004-05-17/15:42:28 64.186.244.42 debug dave Plugin::Systems 33 retrieve(col00129) returning 2 hashes
72476 2004-05-17/15:42:55 64.186.244.42 debug dave Plugin::Systems 33 retrieve(col00129) returning 1 hashes
94474 2004-05-17/15:42:59 64.186.244.42 debug dave Plugin::Systems 33 retrieve(col00129) returning 2 hashes

You can see that when I try to retrieve the new customer, the # of hashes (the number of items the customer has) returned differs depending on the PID of the child. (All children should be returning 2)

Thanks!



Dave Boodman wrote:
As Perrin said, it sounds like it might be a scoping issue with some variables
and how they are (not?) passed into subs. What could really help us spot it
are your subs and calls to them. In fact if you can reduce it to a very simple
test case that has the same experience, it would be easier to spot.

Michael Peters
Venzia

> OK, here's some code:
>
> # systems
>      my @statuses;
>      my (@systems) = Lib::Systems->search( cid => $cid );
>      unless (@systems) { $self->model->log('debug', "systems for '$cid' not
found"); $self->context->throw( 'systems.not_found', 'Systems not found' ); };

>
> Thanks!
>  At 03:40 PM 5/1/2004, Perrin Harkins wrote:
>  Dave Boodman wrote:
>  I'm seeing an issue where I do an insert and upon subsequent requests,
certain children are not returning the newly-inserted data (row), while others
are. Restarting apache fixes this as does waiting for some length of time.
>  Sounds like you have a scoping problem.  You are probably accidentally
creating a closure somewhere that is holding onto old values.  If you can
reduce your code down to an example small enough to post here, we can try to
spot it for you.
>
> - Perrin
>    -- Report problems: http://perl.apache.org/bugs/ Mail list info:
http://perl.apache.org/maillist/modperl.html List etiquette:
http://perl.apache.org/maillist/email-etiquette.html
------- End of Original Message -------


--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to