DBIx::Class error "Can't find source for XXX"

959 views Asked by At

When I try to dump database with Fixtures:

dbic-migration --schema_class App::Schema --database PostgreSQL -Ilib dump_all_sets

I got error:

DBIx::Class::Schema::source(): Can't find source for Schet at /home/xxx/lib/perl5/x86_64-linux/Moose/Meta/Method/Delegation.pm line 110

In main application I have no problem to write:

$schema->resultset('Schet')

How to fix this error and dump data into fixtures?

3

There are 3 answers

0
Eugen Konkov On

in the DBIx::Class::Schema::Loader we are connecting to the temporary schema.

When connection occur the schema is cloned

But because of there only schema name is passed nothing is cloned and, as result, has empty class mapping. Which is wrong.

If you look carefully you will see that cloning occur twice: here and here. This extra cloning is wasteful and should be refactored.

As work around here should be passed reblessed into required namespace cloned schema:

sub _make_schema_at {
  my ($self, $name, %extra_opts) = @_;
  my $schema = $self->schema->clone;
  bless $schema, $name;
  DBIx::Class::Schema::Loader::make_schema_at
    $schema, {_merge_opts(%extra_opts)}, [{_rearrange_connect_info($schema->storage)}];
}

UPD

Lately, when new loader is created, the naming is forced to current instead of passed argument, which, in its turn, is cloned from application schema. (I do not check that, but when application will have its own naming, this will cause problems when dumping data) and loader is invoked again. Here loader loads classes based on table names instead of package names( how it is done at __PACKAGE__->load_namespaces( ... ) )

Finally @to_register lists differ:

Here

[
  Ip,
  App::Schema0::Result::Ip,
]
[
  Scheta,
  App::Schema0::Result::Scheta,
]

Here:

[
  IP,
  App::Schema::Result::IP,
],
[
  Schet,
  App::Schema::Result::Schet,
],
0
Terry On

Ran into this recently, within a docker container. Curiously, some DBIx directories had the wrong permissions on them. They need to at least be readable. Also check file/directory ownership.

0
Dan On

Like @bliako above, I ran into this error (albeit intermittently) when the DBIx::Class source was named with a capital letter, e.g. "Foo" with a table all lower, e.g. "foo"

Once I renamed the table, error so far has gone away. In 10+ yrs of using this module I had never seen this before.