FAQ
This is probably not directly a Catalyst issue, but perhaps someone on
this list can help.

I have an 'update' method in my controller that saves off the changes to
a record. Pertinent code is:

$site =
BirdWeb::Admin::M::BirdWebDB::BirdingSites->retrieve($parms->{id});
eval {
$site->update_from_form( $checked );
$site->update();
};

The changes are being written to the database.

At the end of "update" I forward control to the "list" method. This
method runs a query against the database and returns results. It works
fine if called directly.

However, if the call comes from the update then the record that was
written to the database comes back incorrectly. A data dump shows the
problem:

<snip>
bless( {
'id' => '8',
'site_name' => 'Brand
new site 1',
'ecoregion_name' =>
'region 1'
},
'BirdWeb::Admin::M::BirdWebDB::BirdingSites' ),
bless( {
'__Changed' => {},
'id' => '9'
},
'BirdWeb::Admin::M::BirdWebDB::BirdingSites' ),

<snip>

Why is id 9 not the same as the id 8? It was the record most recently
changed, but the changes were saved. Is there something I need to do to
clear the object from memory?

Thanks!

- Alan

Search Discussions

  • Andy Grundman at May 11, 2005 at 7:49 pm

    Alan Humphrey wrote:
    eval {
    $site->update_from_form( $checked );
    $site->update();
    };
    This may not fix your problem, but you don't need to call update if you
    are using update_from_form. Try removing the update call.

    -Andy
  • Perrin Harkins at May 11, 2005 at 7:55 pm

    On Wed, 2005-05-11 at 10:43 -0700, Alan Humphrey wrote:
    Is there something I need to do to
    clear the object from memory?
    If you are using InnoDB tables, set your isolation level to
    READ_COMMITTED. Otherwise, try this in your startup.pl:
    $Class::DBI::Weaken_Is_Available = 0;

    There is discussion of this on the wiki at http://class-dbi.com/.

    - Perrin
  • Alan Humphrey at May 11, 2005 at 11:30 pm
    Many thanks! The discussion you pointed me to included another
    alternative, which is working for me.

    $site =
    BirdWeb::Admin::M::BirdWebDB::BirdingSites->retrieve($parms->{id});
    eval {
    $site->update_from_form( $checked );
    $site->remove_from_object_index();
    };

    The "remove_from_object_index" call does the trick.

    - Alan

    -----Original Message-----
    From: Perrin Harkins
    Sent: Wednesday, May 11, 2005 9:56 AM
    To: Alan Humphrey
    Cc: catalyst@lists.rawmode.org
    Subject: Re: [Catalyst] CDBI issue?
    On Wed, 2005-05-11 at 10:43 -0700, Alan Humphrey wrote:
    Is there something I need to do to
    clear the object from memory?
    If you are using InnoDB tables, set your isolation level to
    READ_COMMITTED. Otherwise, try this in your startup.pl:
    $Class::DBI::Weaken_Is_Available = 0;

    There is discussion of this on the wiki at http://class-dbi.com/.

    - Perrin
  • Perrin Harkins at May 11, 2005 at 11:32 pm

    On Wed, 2005-05-11 at 14:31 -0700, Alan Humphrey wrote:
    Many thanks! The discussion you pointed me to included another
    alternative, which is working for me.

    $site =
    BirdWeb::Admin::M::BirdWebDB::BirdingSites->retrieve($parms->{id});
    eval {
    $site->update_from_form( $checked );
    $site->remove_from_object_index();
    };

    The "remove_from_object_index" call does the trick.
    Cool. Keep in mind that this *does* mean you have a scoping problem
    with this object. I don't know if that's because of Catalyst or not,
    but some reference to this object in your code (or in Catalyst) is not
    going away at the end of the request.

    - Perrin
  • Andy Grundman at May 11, 2005 at 11:38 pm

    Perrin Harkins wrote:
    Cool. Keep in mind that this *does* mean you have a scoping problem
    with this object. I don't know if that's because of Catalyst or not,
    but some reference to this object in your code (or in Catalyst) is not
    going away at the end of the request.
    FYI, I've had scoping problems with other applications I've written but
    so far in 3 different Catalyst apps I've worked on, I haven't seen a
    problem with it at all.

    -Andy
  • Alan Humphrey at May 11, 2005 at 11:49 pm
    Cool. Keep in mind that this *does* mean you have a scoping problem
    with this object. I don't know if that's because of Catalyst or not,
    but some reference to this object in your code (or in Catalyst) is not
    going away at the end of the request.

    -> Yeah, I was thinking about that. The object is created in the
    "update" method. The only thing I can think of is that "forward" is not
    the same thing as a subroutine call and somehow keeps objects in scope.

    Any thoughts from someone with a deeper understanding of what's
    happening under the hood?
  • Sebastian Riedel at May 12, 2005 at 1:25 am

    Am 11.05.2005 um 23:51 schrieb Alan Humphrey:
    -> Yeah, I was thinking about that. The object is created in the
    "update" method. The only thing I can think of is that "forward"
    is not
    the same thing as a subroutine call and somehow keeps objects in
    scope.

    Any thoughts from someone with a deeper understanding of what's
    happening under the hood?
    Scoping should work like for normal sub calls.

    --
    sebastian

    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20050512/5733cd69/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMay 11, '05 at 7:42p
activeMay 12, '05 at 1:25a
posts8
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase