Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

myapp_local.yml gets ignored

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


jochen.luig at skytel

Jun 17, 2009, 6:50 AM

Post #1 of 9 (689 views)
Permalink
myapp_local.yml gets ignored

Hi,

I'm currently writing tests for an application. To be able to test with
a live database, I wrote a test database package along the lines of the
example in chapter 8 (page 165) of Johnathan's Catalyst book:

package MyApp::Test::Database::Live;

use strict;
use warnings;

use MyAppDB;
use MyApp::Model::MyAppDB;
use Directory::Scratch;
use YAML qw( DumpFile );
use FindBin qw( $Bin );
use Digest::SHA1 qw( sha1_hex );
use HTTP::Request;

use base 'Exporter';
our @EXPORT = qw /schema log_in /;
my $schema;
my $config;

BEGIN {
my $tmp = Directory::Scratch->new;
my $db = $tmp->touch('db');
my $dsn = "DBI:SQLite:$db";
$schema = MyAppDB->connect($dsn);
$schema->deploy;
$config = "$Bin/../myapp_local.yml";
DumpFile($config, { 'MyApp::Model::MyAppDB' => { connect_info =>
[$dsn]}});
DumpFile('/home/jochen/location.txt', { 'path' => $config });
}

sub schema { $schema };

sub log_in {
my $mech = shift;

my $obj = '{ "login": "testuser", "password": "testing"}' . "\n";
my $dummy = [ 'Content-type' => 'application/json', 'Content-Length'
=> length($obj) ];
my $user = schema()->resultset('MyAppDB::User')->create({
login => 'testuser',
password => sha1_hex('testing'),
#password => 'testing',
mail => 'testuser[at]mydomain.com',
first_name => 'Max',
last_name => 'Mustermann',
company => 'mycompany',
customer_id => '002096',
});
my $req = HTTP::Request->new('POST',
'http://localhost/rest/login/login', $dummy, $obj);
$mech->request($req);
return $user;
}

END { unlink $config };

1;

When the login request failed, I first thought it had to do with the
authentication process. But when there was a change in the db schema
that I hadn't made accordingly in my local mysql database, the test
script complained about the columns not present in the database. So the
myapp_local.yml seems to get ignored. OTOH, the test user is not created
in that database.
According to the ConfigLoader docs, 'local' is the default suffix for
files used to override the main config, so AFAIU the above code is
supposed to "just work".
Maybe I'm just not seeing the wood for the trees here, but are there any
prerequisites for this to work that I may have overlooked?

Jochen


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


ben-catalyst at vinnerd

Jun 17, 2009, 7:58 AM

Post #2 of 9 (646 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On 17/06/09 14:50, Jochen Luig wrote:
> <snip> So the
> myapp_local.yml seems to get ignored. OTOH, the test user is not created
> in that database.
> According to the ConfigLoader docs, 'local' is the default suffix for
> files used to override the main config, so AFAIU the above code is
> supposed to "just work".
> Maybe I'm just not seeing the wood for the trees here, but are there any
> prerequisites for this to work that I may have overlooked?
>
>
This looks like the same problem i'm having (see thread "ConfigLoader
trouble").

I did try myapp_local.conf and it was ignored.

Ben


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


c.a.vincent at newcastle

Jun 17, 2009, 8:13 AM

Post #3 of 9 (646 views)
Permalink
RE: myapp_local.yml gets ignored [In reply to]

>-----Original Message-----
>From: Ben Vinnerd [mailto:ben-catalyst[at]vinnerd.com]
>Sent: 17 June 2009 15:59
>To: The elegant MVC web framework

>On 17/06/09 14:50, Jochen Luig wrote:
>> <snip> So the
>> myapp_local.yml seems to get ignored. OTOH, the test user is not
>created
>> in that database.
>> According to the ConfigLoader docs, 'local' is the default suffix
>for
>> files used to override the main config, so AFAIU the above code is
>> supposed to "just work".
>> Maybe I'm just not seeing the wood for the trees here, but are there
>any
>> prerequisites for this to work that I may have overlooked?


>This looks like the same problem i'm having (see thread "ConfigLoader
>trouble").
>
>I did try myapp_local.conf and it was ignored.


Are you sure that your config files are parsing correctly? I've had problems in the past (admittedly with YAML config files) with the files being silently ignored when there's a syntax error in them. This may be handled better in the latest versions.

Regards

Carl


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Carl Vincent http://www.netskills.ac.uk/ (URL)
Systems Manager 0191 222 5003 (voice)
Netskills, Newcastle University 0191 222 5001 (fax)
Training — Accreditation - Consultancy — Development


ben-catalyst at vinnerd

Jun 17, 2009, 8:20 AM

Post #4 of 9 (644 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On 17/06/09 16:13, Carl Vincent wrote:
> Are you sure that your config files are parsing correctly? I've had problems in the past (admittedly with YAML config files) with the files being silently ignored when there's a syntax error in them. This may be handled better in the latest versions.

Yeah i'm sure - if i load the config file manually from within
lib/Myapp.pm, it works fine:

__PACKAGE__->config->{'Plugin::ConfigLoader'} = {file =>
'/home/motoring/Motoring/motoring_beta.conf'};

($ENV{MOTORING_CONFIG_LOCAL_SUFFIX} is set to "beta")

Ben


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


jochen.luig at skytel

Jun 17, 2009, 8:28 AM

Post #5 of 9 (645 views)
Permalink
RE: myapp_local.yml gets ignored [In reply to]

On Wed, 2009-06-17 at 16:13 +0100, Carl Vincent wrote:

> Are you sure that your config files are parsing correctly? I've had problems in the past (admittedly with YAML config files) with the files being silently ignored when there's a syntax error in them. This may be handled better in the latest versions.
>

As mine is written via the DumpFile function of the YAML module, I think
it will parse correctly. Anyway, here's a sample myapp_local.yml

---
MyApp::Model::MyAppDB:
connect_info:
- DBI:SQLite:/tmp/8UwA7IjIPZ/db

Looks OK to me.


@Ben: Sorry, I found your thread only after I had written my message.
But yes, looks like it's the same problem.

Regards,

Jochen


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


bobtfish at bobtfish

Jun 18, 2009, 12:50 AM

Post #6 of 9 (628 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On 17 Jun 2009, at 14:50, Jochen Luig wrote:
> According to the ConfigLoader docs, 'local' is the default suffix for
> files used to override the main config, so AFAIU the above code is
> supposed to "just work".
> Maybe I'm just not seeing the wood for the trees here, but are
> there any
> prerequisites for this to work that I may have overlooked?

Erm, no. It should just work.

I generated an example app with: catalyst.pl TestConfig, and applied
the attached patch - this shows the local config happening.

At a wild stab in the dark - is this an issue with the lifecycle of
your application? I.e. is your app starting before you actually write
the config file out?

I guess that starting your test with strace -f and then searching for
instances of the string 'myapp_local' in the output would be
instructive about what is going wrong for you..

Cheers
t0m
Attachments: 0001-Test-local-config-works.patch (2.52 KB)


ben-catalyst at vinnerd

Jun 18, 2009, 7:27 AM

Post #7 of 9 (619 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On 17/06/09 14:50, Jochen Luig wrote:
> When the login request failed, I first thought it had to do with the
> authentication process. But when there was a change in the db schema
> that I hadn't made accordingly in my local mysql database, the test
> script complained about the columns not present in the database. So the
> myapp_local.yml seems to get ignored. OTOH, the test user is not created
> in that database.
> According to the ConfigLoader docs, 'local' is the default suffix for
> files used to override the main config, so AFAIU the above code is
> supposed to "just work".
> Maybe I'm just not seeing the wood for the trees here, but are there any
> prerequisites for this to work that I may have overlooked?
>
>

Jochen - have you deleted the Makefile.PL in the app dir? If so, put it
back :)

Ben


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


jochen.luig at skytel

Jun 19, 2009, 12:20 AM

Post #8 of 9 (602 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On Thu, 2009-06-18 at 15:27 +0100, Ben Vinnerd wrote:

> Jochen - have you deleted the Makefile.PL in the app dir? If so, put it
> back :)

No, it's still there. I'm not familiar with the startup process of
Catalyst apps and couldn't find anything beyond this part of the manual:

http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/Internals.pod#Initialization

but I suspect my problem is that the db connection is configured in
MyApp::Model::MyAppDB in an if statement that looks at the hostname and
then sets it according to the present environment. I'll try it with %ENV
and config files the way you're doing it next.

Jochen

P.S.: If there's a more in depth documentation on the initialization
process, I'd appreciate a link.


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


jochen.luig at skytel

Jun 19, 2009, 12:27 AM

Post #9 of 9 (602 views)
Permalink
Re: myapp_local.yml gets ignored [In reply to]

On Thu, 2009-06-18 at 08:50 +0100, Tomas Doran wrote:

> At a wild stab in the dark - is this an issue with the lifecycle of
> your application? I.e. is your app starting before you actually write
> the config file out?

It may be a lifecycle issue. The db connection is configured in
MyApp::Model::MyAppDB. I don't know enough about the initialization
process to decide if that's a problem, so I'll just try it.

> I guess that starting your test with strace -f and then searching for
> instances of the string 'myapp_local' in the output would be
> instructive about what is going wrong for you..

As far as I understand the attached snippet of the strace output I think
the myapp_local.yml is actually being read during the startup process.

Jochen
Attachments: strace_snippet.txt (3.13 KB)

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.