srchulo / Catalyst--Model--DBIx--Raw

A Catalyst::Model for DBIx::Raw
0 stars 1 forks source link

Can't find DBIx::Class when using dbix_class_model #1

Open RobertCarew opened 9 years ago

RobertCarew commented 9 years ago

When I use dbix_class_model in my config rather than dsn etc. I get the error "Can't call method "storage" on an undefined value". It would appear that Catalyst::Model::DBIx::Raw->new is called before the DBIx components have been loaded. It works if I specify dsn, user, password in the config, but I want to use the existing DBIx::Class connection. Any suggestions.

srchulo commented 9 years ago

Hmm..that's interesting because I have projects using that that work. @RobertCarew for your Catalyst::Model::DBIx::Raw config, do you have it using the name of your dbix_class_model, and not just what I have in my example?

PACKAGE->config( dbix_class_model => 'NameOfYourDBModel', );

Because I think that could be another reason for that error.

RobertCarew commented 9 years ago

Hi Adam Sorry for the delay it is summer holidays here in New Zealand and I have just returned.

Yes I used my own model name although I wasn't sure if I should use the package name or the schema class name, i.e. my package is

SAMDDB.pm package SAMD::Model::SAMDDB;

use strict; use base 'Catalyst::Model::DBIC::Schema';

PACKAGE->config( schema_class => 'SAMD::SAMDDB', );

1;

My Raw.pm is package SAMD::Model::Raw; use parent 'Catalyst::Model::DBIx::Raw';

use strict;

use warnings;

PACKAGE->config(

dbix_class_model => 'SAMDDB',

dbix_class_model => 'SAMD::SAMDDB',

dsn =>

'dbi:ODBC:DSN=samd;trusted_connection=YES;mars_connection=YES',

user => 'residues',

password => 'pw',

);

1;

I made a copy of a Catalyst module and did a data::Dump of the component array which showed only the View::JSON and View::TT had been loaded at that point. I think it is a timing issue - my Raw.pm is being loaded before the DB models. Also I noticed a typo on line 36 of package Catalyst::Model::DBIx::Raw; It reads: dns => $self->{dsn}, and should read dns => $self->{dsn},

How do I get the DB models to load before my Raw model?

Thanks for any help Regards Robert Carew

On 24 December 2014 at 05:17, Adam Hopkins notifications@github.com wrote:

Hmm..that's interesting because I have projects using that that work. @RobertCarew https://github.com/RobertCarew for your Catalyst::Model::DBIx::Raw config, do you have it using the name of your dbix_class_model, and not just what I have in my example?

PACKAGE->config( dbix_class_model => 'NameOfYourDBModel', );

Because I think that could be another reason for that error.

— Reply to this email directly or view it on GitHub https://github.com/srchulo/Catalyst--Model--DBIx--Raw/issues/1#issuecomment-67967918 .

Wine is sunlight held together by water - Galileo

srchulo commented 9 years ago

Hi @RobertCarew

Sorry for the delay. I think I have a fix, but unfortunately upgrading to Yosemite has completely messed up my perl (and just in general my coding) environment. So I have to redownload a lot of my perl modules before I can test and push it out, and Yosemite is definitely making it harder than it has to be :) So I just wanted to let you know that I am working on this, but it might be a couple of days.

RobertCarew commented 9 years ago

Great, thanks for that. Anything I can do to help. I am working on a client site with Redhat Linux 2.6.18 and Perl 5.10.1.

Robert

On 8 January 2015 at 05:53, Adam Hopkins notifications@github.com wrote:

Hi @RobertCarew https://github.com/RobertCarew

Sorry for the delay. I think I have a fix, but unfortunately upgrading to Yosemite has completely messed up my perl (and just in general my coding) environment. So I have to redownload a lot of my perl modules before I can test and push it out, and Yosemite is definitely making it harder than it has to be :) So I just wanted to let you know that I am working on this, but it might be a couple of days.

— Reply to this email directly or view it on GitHub https://github.com/srchulo/Catalyst--Model--DBIx--Raw/issues/1#issuecomment-69051884 .

Wine is sunlight held together by water - Galileo

srchulo commented 9 years ago

@RobertCarew, I wanted to let you know that I haven't forgotten about this. I still haven't gotten my environment working properly again, and I'm actually traveling right now to see family so there might be a delay until I can sort this all out. But, I know that you said you were working on something for a client and I didn't want you to be held up. I've posted this here:

http://pastebin.com/MhRpSUFy

I think that this might be a fix. I can't test it, or even run perl -c (because the modules aren't installed on my computer), but I think that it should be pretty close and I think will do what you need (assuming that the issue is that Catalyst is loading Catalyst::Model::DBIx::Raw before the DBIx components). I will try to get a permanent fix up on CPAN as soon as I can. Please let me know if you have any questions about that fix or if there's anyway I can you help you get that working temporarily.

Thanks!

RobertCarew commented 9 years ago

Hi Adam Thanks for the update. Sadly it didn't work. I added a catch after the first try and got the same error message. I then tried using the Moose after 'setup_components' as illustrated in the article http://www.perlmonks.org/?node_id=915657. This gave the error that setup_components was not in the Hierarchy. So then I renamed my module to SAMDRaw.pm so that it came after Raw.pm in the directory. Then it worked - a quick and dirty solution. When I say it worked it loaded my Raw module however I now get an error with ODBC + Kerberos which I am still trying to understand.We are running an Apache webserver under Tophat Linux connecting to MS SQLServer using ODBC and Kerberos. The clients choice not mine. And obviously not an issue with DBIx::Raw. In the meantime I've reverted to using the explicit config parameters dsn, user, password.

Thanks for your help so far. It would be good to get it working properly but the pressure is off now.

Cheers Robert

On 10 January 2015 at 12:22, Adam Hopkins notifications@github.com wrote:

@RobertCarew https://github.com/RobertCarew, I wanted to let you know that I haven't forgotten about this. I still haven't gotten my environment working properly again, and I'm actually traveling right now to see family so there might be a delay until I can sort this all out. But, I know that you said you were working on something for a client and I didn't want you to be held up. I've posted this here:

http://pastebin.com/MhRpSUFy

I think that this might be a fix. I can't test it, or even run perl -c (because the modules aren't installed on my computer), but I think that it should be pretty close and I think will do what you need (assuming that the issue is that Catalyst is loading Catalyst::Model::DBIx::Raw before the DBIx components). I will try to get a permanent fix up on CPAN as soon as I can. Please let me know if you have any questions about that fix or if there's anyway I can you help you get that working temporarily.

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/srchulo/Catalyst--Model--DBIx--Raw/issues/1#issuecomment-69418099 .

Wine is sunlight held together by water - Galileo

srchulo commented 9 years ago

@RobertCarew, what module did you rename to SAMDRaw.pm? And what version of Catalyst are you using? I'm having trouble reproducing the error, so I'm just trying to make sure that I'm doing what you did. Thanks!

RobertCarew commented 9 years ago

Hi Adam

Catalyst version is [2015/01/13 09:34:30] [catalyst] [INFO] samd powered by Catalyst 5.90020

This is my SAMDRaw.pm which was called Raw.pm It is in the Catalyst Model directory along with SAMDDB.pm which pulls in my DB domain. When this module was called Raw.pm it appeared before the SAMDDB.pm in the directory and was loaded before it. By changing the name to SAMDRaw it now comes after SAMDDB.pm and so all my DB result components have been loaded and everything is ok.

package SAMD::Model::SAMDRaw; use parent 'Catalyst::Model::DBIx::Raw';

use strict;

use warnings;

use Data::Dumper;

PACKAGE->config(

conf => 'conf/samd_raw.conf',

dbix_class_model => 'SAMDDB',

dbix_class_model => 'SAMD::SAMDDB',

dsn =>

'dbi:ODBC:DSN=samd;trusted_connection=YES;mars_connection=YES',

user => 'residues',

password => 'pw',

dsn => SAMD->config->{'Model::SAMDDB'}->{'connect_info'}->{dsn},
user => SAMD->config->{'Model::SAMDDB'}->{'connect_info'}->{user},
password =>

SAMD->config->{'Model::SAMDDB'}->{'connect_info'}->{password},

);

1;

SAMDDB.pm package SAMD::Model::SAMDDB;

use strict; use base 'Catalyst::Model::DBIC::Schema';

PACKAGE->config( schema_class => 'SAMD::SAMDDB', );

1;

Until I sort out the problem with ODBC/Kerberos I am picking up the config info from my Catalyst config file. This means I have an extra connection to the database.

Hope this explains everything.

Cheers Robert

On 13 January 2015 at 06:18, Adam Hopkins notifications@github.com wrote:

@RobertCarew https://github.com/RobertCarew, what module did you rename to SAMDRaw.pm? And what version of Catalyst are you using? I'm having trouble reproducing the error, so I'm just trying to make sure that I'm doing what you did. Thanks!

— Reply to this email directly or view it on GitHub https://github.com/srchulo/Catalyst--Model--DBIx--Raw/issues/1#issuecomment-69606990 .

Wine is sunlight held together by water - Galileo