[Dbix-class] Row object does not work correctly after thaw.

Oleg Pronin syber.rus at gmail.com
Fri May 8 11:01:36 GMT 2009

Thanks! But i have serveral databases (several schema classes).

Temporarily i placed this piece of code into framework's base resultsource
which automatically gets the right schema on thaw and support several
schemas but works only under catalyst project.

our %schema_thaw_cache;
sub STORABLE_thaw {
    my ($self, $cloning, $serialized) =3D @_;

# too early to setup $DBIx::Class::ResultSourceHandle::thaw_schema here
# content is not deserialized yet and we do not know yet which schema to

    %$self =3D %{Storable::thaw($serialized)};

    my $class =3D ref $self;
    my $schema =3D $schema_thaw_cache{$class}; #try cache for x4 speedup

    unless ($schema) {
        return unless index($class, '::Model::') >=3D 0; #possible under
        my $app =3D substr($class, 0, index($class, ':')) or return;
        return unless $app->isa('Catalyst');
        (my $comp =3D $class) =3D~ s/^${app}::Model:://;
        my $rs =3D $app->model($comp) or return;
        $schema =3D $schema_thaw_cache{$class} =3D $rs->result_source->sche=
    #insert correct schema

I don't like it :-)

I think this could be handled by DBIC itself by means of storing
MyDB::Schema->instance singletons (stored on first MyDB::Schema->connect).
And on restore it could get $schema_class->instance.

This will work ok for 99% people (except for those who use the same schema
connected to more that one databases at once and those who update such rows)

2009/5/8 Ash Berlin <ash_cpan at firemirror.com>

> On 8 May 2009, at 10:09, Oleg Pronin wrote:
> Hello.
> DBIx::Class::ResultSourceHandle has storable hooks to correctly store row
> object and restore it.
> However after restore, trying to update such an object will fail:
> Can't call method "update" on an undefined value at
> /usr/local/lib/perl5/site_perl/5.10.0/DBIx/Class/Row.pm line 490.
> Because $obj->result_source->schema isn't a correct schema,
> $obj->result_source->schema->storage is undefined
> It would be great to attach correct schema. Can someone fix that?
> This is because you thawed it 'wrong'.
> This http://search.cpan.org/perldoc?DBIx::Class::ResultSourceHandle says
> the following about thawing:
> Thaws frozen handle. Resets the internal schema reference to the package
> variable $thaw_schema. The recomened way of setting this is to use
> $schema->thaw($ice) which handles this for you.
> Alternatively, if you use Catalyst you can set
> local $DBIx::Class::ResultSourceHandle::thaw_schema =3D
> $c->model('MyDBIC')->schema;
> or similar somewhere near the start of your request (can't be in an actio=
> it wouldn't localize right)
> -ash
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090508/f47=

More information about the DBIx-Class mailing list