FAQ
Hey folks,

our app is using the following old and rather obscure hack which
injects some custom SQL to perform a UNION.
This works perfectly with the latest DBIC 0.08123 and
Catalyst::Runtime 5.80007. However, after upgrading
to the latest Catalyst::Runtime 5.80025 the app doesn't start anymore
giving this error:

Couldn't load class (MyApp) because:
DBIx::Class::Row::throw_exception(): Can't locate object method
"register_source" via package "MyApp::Schema" at
xxx/MyApp/Schema/User.pm line 357 (see line below).

Any ideas on how to fix this? Please don't tell me to avoid the UNION
altogether because we don't want
to change this ATM. I'm aware that there's
DBIx::Class::ResultSource::View, but this doesn't quite do what
we want, because the view fetching all those friendships between users
would have to return a Schema::User
not Schema::FriendshipView ResultSet. Or am I missunderstanding this
whole virtual view thing? :)

Thanks a lot!

--Tobias


# Mutual friendships
my $source = __PACKAGE__->result_source_instance();
my $source_mutual = $source->new( $source );

# Workaround by mst for the class-based name lookup problems
# when building custom SQL via result_source_instance().
# See: http://www.mail-archive.com/dbix-class@lists.rawmode.org/msg03490.html
@MyApp::Schema::UserView::ISA = ('MyApp::Schema::User');
$source_mutual->result_class( 'MyApp::Schema::UserView' );

$source_mutual->source_name( 'UserMutualFriends' );

my $friendship_sql = qq|SELECT f.id AS friendship_id, u.* FROM users u
INNER JOIN friendships f ON u.id = f.initiator_user_id
WHERE f.receiver_user_id = ?
AND f.date_confirmed IS NOT NULL
UNION
SELECT f.id AS friendship_id, u.* FROM users u
INNER JOIN friendships f ON u.id = f.receiver_user_id
WHERE f.initiator_user_id = ?
AND f.date_confirmed IS NOT NULL|;

$source_mutual->name( \"(${friendship_sql})" );
$source_mutual->add_column( 'friendship_id' );

# Line 357 that breaks latest Catalyst:
MyApp::Schema->register_source( 'MyApp::Schema::MutualFriends' =>
$source_mutual );

Search Discussions

  • Tomas Doran at Aug 6, 2010 at 3:40 pm

    On 6 Aug 2010, at 16:44, Tobias Kremer wrote:

    Hey folks,

    our app is using the following old and rather obscure hack which
    injects some custom SQL to perform a UNION.
    This works perfectly with the latest DBIC 0.08123 and
    Catalyst::Runtime 5.80007. However, after upgrading
    to the latest Catalyst::Runtime 5.80025 the app doesn't start anymore
    giving this error:

    Couldn't load class (MyApp) because:
    DBIx::Class::Row::throw_exception(): Can't locate object method
    "register_source" via package "MyApp::Schema" at
    xxx/MyApp/Schema/User.pm line 357 (see line below).
    Can you load Devel::SimpleTrace and get a full stack trace of the
    failure?

    Cheers
    t0m
  • Tobias Kremer at Aug 9, 2010 at 10:24 am
    Hey t0m,
    Couldn't load class (MyApp) because:
    DBIx::Class::Row::throw_exception(): Can't locate object method
    "register_source" via package "MyApp::Schema" at
    xxx/MyApp/Schema/User.pm line 357 (see line below).
    Can you load Devel::SimpleTrace and get a full stack trace of the failure?
    Sure, see below.

    Is it possible that this has got something to do with me explicitly
    use'ing some Schema classes in controllers because they have some
    constants defined that I need to access? For instance,
    Controller::Club, line 7 says: use MyApp::Schema::Club which provides
    something like MyApp::Schema::Club::MAX_NO_OF_FOO that is used within
    the controller.

    Thanks for your help!
    --Tobias


    Couldn't load class (MyApp) because:
    DBIx::Class::Row::throw_exception(): Can't locate object method
    "register_source" via package "MyApp::Schema"
    at (/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Class/C3/Componentised.pm:128)
    at Class::C3::Componentised::ensure_class_loaded(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Class/C3/Componentised.pm:128)
    at DBIx::Class::Relationship::BelongsTo::belongs_to(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/DBIx/Class/Relationship/BelongsTo.pm:28)
    at (/home/dev/MyApp/script/../lib/MyApp/Controller/Club.pm:7)
    at (/home/dev/MyApp/script/../lib/MyApp/Schema/User.pm)
    at (/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Utils.pm:281)
    at Catalyst::setup_components(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst.pm:2423)
    at Catalyst::setup(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst.pm:1157)
    at (/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm:114)
    at (/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Try/Tiny.pm:67)
    at Class::MOP::load_first_existing_class(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm:125)
    at Class::MOP::load_class(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm:137)
    at Catalyst::ScriptRole::_run_application(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/ScriptRole.pm:61)
    at Catalyst::Script::Server::__ANON__(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Script/Server.pm:144)
    at Catalyst::Restarter::Forking::_fork_and_start(/usr/local/share/perl/5.10.0/Catalyst/Restarter/Forking.pm:20)
    at Catalyst::Restarter::run_and_watch(/usr/local/share/perl/5.10.0/Catalyst/Restarter.pm:89)
    at Catalyst::Script::Server::run(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Script/Server.pm:178)
    at Class::MOP::Method::Wrapped::__ANON__(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm:48)
    at Catalyst::Script::Server::run(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm:89)
    at Catalyst::ScriptRunner::run(/home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/ScriptRunner.pm:20)
    at main::(script/MyApp_server.pl:8)
    Compilation failed in require at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Class/C3/Componentised.pm
    line 128.
    Compilation failed in require at
    /home/dev/MyApp/script/../lib/MyApp/Controller/Club.pm line 7.
    BEGIN failed--compilation aborted at
    /home/dev/MyApp/script/../lib/MyApp/Controller/Club.pm line 7.
    Compilation failed in require at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Utils.pm line 281.
    Compilation failed in require at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm
    line 114.
    at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm
    line 120
    Class::MOP::__ANON__('DBIx::Class::Row::throw_exception(): Can\'t
    locate object met...') called at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Try/Tiny.pm line 98
    Try::Tiny::try('CODE(0x244b918)', 'Try::Tiny::Catch=REF(0x25809a0)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm
    line 125
    Class::MOP::load_first_existing_class('MyApp') called at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP.pm
    line 137
    Class::MOP::load_class('MyApp') called at
    /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/ScriptRole.pm line
    61
    Catalyst::ScriptRole::_run_application('Catalyst::Script::Server=HASH(0x1275f00)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Script/Server.pm
    line 144
    Catalyst::Script::Server::__ANON__() called at
    /usr/local/share/perl/5.10.0/Catalyst/Restarter/Forking.pm line 20
    Catalyst::Restarter::Forking::_fork_and_start('Catalyst::Restarter::Forking=HASH(0x244bca8)')
    called at /usr/local/share/perl/5.10.0/Catalyst/Restarter.pm line 89
    Catalyst::Restarter::run_and_watch('Catalyst::Restarter::Forking=HASH(0x244bca8)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/Script/Server.pm
    line 178
    Catalyst::Script::Server::run('Catalyst::Script::Server=HASH(0x1275f00)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm
    line 48
    Class::MOP::Method::Wrapped::__ANON__('Catalyst::Script::Server=HASH(0x1275f00)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/x86_64-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm
    line 89
    Catalyst::Script::Server::run('Catalyst::Script::Server=HASH(0x1275f00)')
    called at /home/dev/MyApp/dbic_cat_upgrade/lib/perl5/Catalyst/ScriptRunner.pm
    line 20
    Catalyst::ScriptRunner::run('Catalyst::ScriptRunner', 'MyApp',
    'Server') called at script/MyApp_server.pl line 8
  • Tobias Kremer at Aug 9, 2010 at 3:04 pm

    On Mon, Aug 9, 2010 at 12:24 PM, Tobias Kremer wrote:
    Couldn't load class (MyApp) because:
    DBIx::Class::Row::throw_exception(): Can't locate object method
    "register_source" via package "MyApp::Schema" at
    xxx/MyApp/Schema/User.pm line 357 (see line below).
    Can you load Devel::SimpleTrace and get a full stack trace of the failure?
    Is it possible that this has got something to do with me explicitly
    use'ing some Schema classes in controllers because they have some
    constants defined that I need to access?
    My suspicion was right: After removing all "use MyApp::Schema::*"
    occurrences from our controllers the app started. Nevertheless, I'm
    not sure if this is expected behaviour.

    I skimmed through the mailing list archive and found a thread about
    how best to arrange constants and the recommendation was to create a
    separate MyApp::Constants class. But to me it sounds more rational to
    store, say different role IDs as constants in the corresponding
    MyApp::Schema::Role model class...

    Any thoughts?

    --Tobias
  • Alexander Hartmaier at Aug 10, 2010 at 8:29 am
    Hi Tobias,

    I've added a My::Model::Constants namespace which several modules
    containing constants for different parts of my schema and include those
    in my result(set) classes if needed and the cat apps using the model.

    --
    Best regards, Alex


    Am Montag, den 09.08.2010, 17:04 +0200 schrieb Tobias Kremer:
    On Mon, Aug 9, 2010 at 12:24 PM, Tobias Kremer wrote:
    Couldn't load class (MyApp) because:
    DBIx::Class::Row::throw_exception(): Can't locate object method
    "register_source" via package "MyApp::Schema" at
    xxx/MyApp/Schema/User.pm line 357 (see line below).
    Can you load Devel::SimpleTrace and get a full stack trace of the failure?
    Is it possible that this has got something to do with me explicitly
    use'ing some Schema classes in controllers because they have some
    constants defined that I need to access?
    My suspicion was right: After removing all "use MyApp::Schema::*"
    occurrences from our controllers the app started. Nevertheless, I'm
    not sure if this is expected behaviour.

    I skimmed through the mailing list archive and found a thread about
    how best to arrange constants and the recommendation was to create a
    separate MyApp::Constants class. But to me it sounds more rational to
    store, say different role IDs as constants in the corresponding
    MyApp::Schema::Role model class...

    Any thoughts?

    --Tobias

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
    T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
    Handelsgericht Wien, FN 79340b
    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
    Notice: This e-mail contains information that is confidential and may be privileged.
    If you are not the intended recipient, please notify the sender and then
    delete this e-mail immediately.
    *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 6, '10 at 2:44p
activeAug 10, '10 at 8:29a
posts5
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase