[Dbix-class] Row object does not work correctly after thaw.
Matt S Trout
dbix-class at trout.me.uk
Mon May 11 17:34:57 GMT 2009
On Fri, May 08, 2009 at 03:01:36PM +0400, Oleg Pronin wrote:
> 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) = @_;
>
> # too early to setup $DBIx::Class::ResultSourceHandle::thaw_schema here
> because
> # content is not deserialized yet and we do not know yet which schema to
> use.
>
> %$self = %{Storable::thaw($serialized)};
>
> my $class = ref $self;
> my $schema = $schema_thaw_cache{$class}; #try cache for x4 speedup
>
> unless ($schema) {
> return unless index($class, '::Model::') >= 0; #possible under
> catalyst
> my $app = substr($class, 0, index($class, ':')) or return;
> return unless $app->isa('Catalyst');
> (my $comp = $class) =~ s/^${app}::Model:://;
> my $rs = $app->model($comp) or return;
> $schema = $schema_thaw_cache{$class} = $rs->result_source->schema;
> }
> #insert correct schema
> $self->_source_handle->schema($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)
I guess you could store a weak ref to it, once only, and if a second $schema
is ever connected just stop doing that.
But it seems to me like it could be -really- fragile - for example under
mod_perl things often get initialized twice so you could have dev working
and production magically not doing so.
An extra component that handles this, with a reference in the DBIC docs to
its existence, would be fine by me - you'd have to convince me you can make
it much more robust than your initial plan seems to be before I'd consider
it for core ...
--
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
mst (@) shadowcat.co.uk http://shadowcat.co.uk/blog/matt-s-trout/
More information about the DBIx-Class
mailing list