Mailing List Archive

find_or_create_alternate() errors
Hi,

Can anyone help on the following - explaining what's going on, what arguments we should pass to find_or_create_alternate() etc.?

Thanks,
Tom

==Issue==

Within a template calling the following code, which I would expect to
find or create an alternate media if $media exists, actually produces an
error.

===Code called===
my $media = $element->get_related_media;
if($media) {
my $thumbnail = $media->find_or_create_alternate({
file_suffix => '_200x150',
# et_key_name => 'alt_media_container',
element_type => 'alt_media_container',
user => $user,
relate => 0,
transformer => sub {
shift->scale( xpixels => 200, ypixels =>150 );
},
});

===Error this code gives===
Can't locate object method "get_fixed_url" via package
"alt_media_container" (perhaps you forgot to load
"alt_media_container"?) at
/home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2518,
<GEN10> line 1585.

===Alternative error===
Uncommenting et_key_name perhaps more disturbingly gives:

DBD::Pg::st execute failed: ERROR: null value in column
"primary_oc__id" violates not-null constraint
[.for Statement "INSERT INTO media_instance (id, name, description,
media__id, usr__id, version, media_type__id, primary_oc__id,
category__id, file_size, file_name, location, uri, cover_date, note,
checked_out) VALUES (NEXTVAL('seq_media_instance'), ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?)" with ParamValues: 2='Thumbnail for ',
3='13941', 4='1926', 5='0', 6='60'] at
/home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1138, <GEN15> line 1585.

Stack:
[/home/newint/bricolage2/lib/Bric/Util/DBI.pm:1138]
[/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:2175]
[/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:1889]
[/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm:614]

[/home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc:257]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
[/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm:550]
[/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:104]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:157]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm:936]
[/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:141]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]

Error Details (hide)

Fault Class
Bric::Util::Fault::Exception::DA
Description
Data Access Exception
Timestamp
2012-05-11 08:42:22.000000
Package
Bric::Util::DBI
Filename
/home/newint/bricolage2/lib/Bric/Util/DBI.pm
Line
1139

Stack:

Trace begun at /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1139
Bric::Util::DBI::execute('DBI::st=HASH(0x5b672e0)', 'Thumbnail for
st_alphageek_f.jpg', 'Thumbnail for ', 13941, 1926, 0, 60, undef, 1651,
undef, undef, undef, undef, '2012-05-11 15:13:00.000000', undef, 1)
called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
line 2175
Bric::Biz::Asset::Business::Media::_insert_instance('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
line 1889
eval {...} at
/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm line 1857
Bric::Biz::Asset::Business::Media::save('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
called at
/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm line 614
Bric::Biz::Asset::Business::Media::Image::find_or_create_alternate('Bric::Biz::Asset::Business::Media::Image=HASH(0x5787250)',
'HASH(0x5b66f80)') called at
/home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc
line 257
Bric::Util::Burner::Commands::__ANON__ at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c94290)')
called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 1274
HTML::Mason::Request::comp(undef, undef, undef) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
HTML::Mason::Request::call_next('HTML::Mason::Request=HASH(0x5c8af40)')
called at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 550
Bric::Util::Burner::Mason::chain_next('Bric::Util::Burner::Mason=HASH(0x5a81040)')
called at /home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 104
Bric::Util::Burner::Commands::__ANON__ at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 157
HTML::Mason::Component::run_dynamic_sub('HTML::Mason::Component::FileBased=HASH(0x5c99180)',
'main') called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 936
HTML::Mason::Request::call_dynamic('HTML::Mason::Request=HASH(0x5c8af40)',
'main') called at
/home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 141
Bric::Util::Burner::Commands::__ANON__ at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c99180)')
called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 1274
HTML::Mason::Request::comp(undef, undef, undef) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 473
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 425
HTML::Mason::Request::exec('HTML::Mason::Request=HASH(0x5c8af40)')
called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Interp.pm line 342
HTML::Mason::Interp::exec(undef, undef) called at
/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
Bric::Util::Burner::Mason::burn_one('Bric::Util::Burner::Mason=HASH(0x5a81040)',
'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
'Bric::Biz::Category=HASH(0x5c89040)') called at
/home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1585
Bric::Util::Burner::burn_one('Bric::Util::Burner=HASH(0x5a7fee0)',
'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
'Bric::Biz::Category=HASH(0x5c89040)') called at
/home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1022
eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 974
Bric::Util::Burner::preview('Bric::Util::Burner=HASH(0x5a7fee0)',
'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)', 'story', 1926,
undef) called at
/home/newint/bricolage2/lib/Bric/App/Callback/Publish.pm line 117
Bric::App::Callback::Publish::preview('Bric::App::Callback::Publish=HASH(0x19baa10)')
called at /home/newint/bricolage2/comp/workflow/profile/preview/dhandler
line 32
HTML::Mason::Commands::__ANON__('checkout', 1, 'checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x3decdf0)',
'checkout', 1, 'checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 1274
HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1,
'checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
HTML::Mason::Request::call_next('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)',
'checkout', 1) called at /home/newint/bricolage2/comp/autohandler line 7
HTML::Mason::Commands::__ANON__('checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x558b940)',
'checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 1274
HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1) called at
/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 473
eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
line 425
HTML::Mason::Request::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
line 168
HTML::Mason::Request::ApacheHandler::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
line 825
HTML::Mason::ApacheHandler::handle_request('HTML::Mason::ApacheHandler=HASH(0x5372040)',
'Apache=SCALAR(0x5a7fc80)') called at
/home/newint/bricolage2/lib/Bric/App/Handler.pm line 307
eval {...} at /home/newint/bricolage2/lib/Bric/App/Handler.pm line 296
Bric::App::Handler::handler('Apache=SCALAR(0x5a7fc80)') called at
PerlHandler subroutine `Bric::App::Handler::handler' line 1
eval {...} at PerlHandler subroutine `Bric::App::Handler::handler' line 1
==
Re: find_or_create_alternate() errors [ In reply to ]
On 2012-05-11, at 10:51 AM, Tom Ash wrote:

> Hi,
>
> Can anyone help on the following - explaining what's going on, what arguments we should pass to find_or_create_alternate() etc.?

Hey there Tom,

You can find the documentation for find_or_create_alternate under Bric::Biz::Asset::Business::Media::Image
http://bricolagecms.org/docs/current/api/

Was this working before, or is this a new template?

Phillip.

> ==Issue==
>
> Within a template calling the following code, which I would expect to
> find or create an alternate media if $media exists, actually produces an
> error.
>
> ===Code called===
> my $media = $element->get_related_media;
> if($media) {
> my $thumbnail = $media->find_or_create_alternate({
> file_suffix => '_200x150',
> # et_key_name => 'alt_media_container',
> element_type => 'alt_media_container',
> user => $user,
> relate => 0,
> transformer => sub {
> shift->scale( xpixels => 200, ypixels =>150 );
> },
> });
>
> ===Error this code gives===
> Can't locate object method "get_fixed_url" via package
> "alt_media_container" (perhaps you forgot to load
> "alt_media_container"?) at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2518,
> <GEN10> line 1585.
>
> ===Alternative error===
> Uncommenting et_key_name perhaps more disturbingly gives:
>
> DBD::Pg::st execute failed: ERROR: null value in column
> "primary_oc__id" violates not-null constraint
> [.for Statement "INSERT INTO media_instance (id, name, description,
> media__id, usr__id, version, media_type__id, primary_oc__id,
> category__id, file_size, file_name, location, uri, cover_date, note,
> checked_out) VALUES (NEXTVAL('seq_media_instance'), ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?)" with ParamValues: 2='Thumbnail for ',
> 3='13941', 4='1926', 5='0', 6='60'] at
> /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1138, <GEN15> line 1585.
>
> Stack:
> [/home/newint/bricolage2/lib/Bric/Util/DBI.pm:1138]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:2175]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:1889]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm:614]
>
> [/home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc:257]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
> [/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm:550]
> [/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:104]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:157]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm:936]
> [/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:141]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
>
> Error Details (hide)
>
> Fault Class
> Bric::Util::Fault::Exception::DA
> Description
> Data Access Exception
> Timestamp
> 2012-05-11 08:42:22.000000
> Package
> Bric::Util::DBI
> Filename
> /home/newint/bricolage2/lib/Bric/Util/DBI.pm
> Line
> 1139
>
> Stack:
>
> Trace begun at /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1139
> Bric::Util::DBI::execute('DBI::st=HASH(0x5b672e0)', 'Thumbnail for
> st_alphageek_f.jpg', 'Thumbnail for ', 13941, 1926, 0, 60, undef, 1651,
> undef, undef, undef, undef, '2012-05-11 15:13:00.000000', undef, 1)
> called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
> line 2175
> Bric::Biz::Asset::Business::Media::_insert_instance('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
> called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
> line 1889
> eval {...} at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm line 1857
> Bric::Biz::Asset::Business::Media::save('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
> called at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm line 614
> Bric::Biz::Asset::Business::Media::Image::find_or_create_alternate('Bric::Biz::Asset::Business::Media::Image=HASH(0x5787250)',
> 'HASH(0x5b66f80)') called at
> /home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc
> line 257
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c94290)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
> HTML::Mason::Request::call_next('HTML::Mason::Request=HASH(0x5c8af40)')
> called at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 550
> Bric::Util::Burner::Mason::chain_next('Bric::Util::Burner::Mason=HASH(0x5a81040)')
> called at /home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 104
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 157
> HTML::Mason::Component::run_dynamic_sub('HTML::Mason::Component::FileBased=HASH(0x5c99180)',
> 'main') called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 936
> HTML::Mason::Request::call_dynamic('HTML::Mason::Request=HASH(0x5c8af40)',
> 'main') called at
> /home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 141
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c99180)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 425
> HTML::Mason::Request::exec('HTML::Mason::Request=HASH(0x5c8af40)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Interp.pm line 342
> HTML::Mason::Interp::exec(undef, undef) called at
> /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
> eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
> Bric::Util::Burner::Mason::burn_one('Bric::Util::Burner::Mason=HASH(0x5a81040)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
> 'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
> 'Bric::Biz::Category=HASH(0x5c89040)') called at
> /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1585
> Bric::Util::Burner::burn_one('Bric::Util::Burner=HASH(0x5a7fee0)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
> 'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
> 'Bric::Biz::Category=HASH(0x5c89040)') called at
> /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1022
> eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 974
> Bric::Util::Burner::preview('Bric::Util::Burner=HASH(0x5a7fee0)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)', 'story', 1926,
> undef) called at
> /home/newint/bricolage2/lib/Bric/App/Callback/Publish.pm line 117
> Bric::App::Callback::Publish::preview('Bric::App::Callback::Publish=HASH(0x19baa10)')
> called at /home/newint/bricolage2/comp/workflow/profile/preview/dhandler
> line 32
> HTML::Mason::Commands::__ANON__('checkout', 1, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x3decdf0)',
> 'checkout', 1, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1,
> 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
> HTML::Mason::Request::call_next('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)',
> 'checkout', 1) called at /home/newint/bricolage2/comp/autohandler line 7
> HTML::Mason::Commands::__ANON__('checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x558b940)',
> 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 425
> HTML::Mason::Request::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
> line 168
> HTML::Mason::Request::ApacheHandler::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
> line 825
> HTML::Mason::ApacheHandler::handle_request('HTML::Mason::ApacheHandler=HASH(0x5372040)',
> 'Apache=SCALAR(0x5a7fc80)') called at
> /home/newint/bricolage2/lib/Bric/App/Handler.pm line 307
> eval {...} at /home/newint/bricolage2/lib/Bric/App/Handler.pm line 296
> Bric::App::Handler::handler('Apache=SCALAR(0x5a7fc80)') called at
> PerlHandler subroutine `Bric::App::Handler::handler' line 1
> eval {...} at PerlHandler subroutine `Bric::App::Handler::handler' line 1
> ==

--
Phillip Smith
http://phillipadsmith.com
http://twitter.com/phillipadsmith
http://linkedin.com/in/phillipadsmith

Save our in-boxes! http://emailcharter.org
Re: find_or_create_alternate() errors [ In reply to ]
Hi Tom,

If you use the "element_type" argument, it needs an element type object,
not just its name. So something like this:

element_type => Bric::Biz::ElementType->lookup({key_name =>
alt_media_container})

But et_key_name normally works just fine, so probably there's something
else going on. I suggest removing the element_type argument, and
uncommenting the et_key_name one, because the error you're seeing in the
second case is the one that really needs solving.

Is alt_media_container a top_level Image media document type? (It can't
be a subelement type.)

Hope this helps,

Bret



--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com


On Fri, 2012-05-11 at 16:51 +0100, Tom Ash wrote:
> Hi,
>
> Can anyone help on the following - explaining what's going on, what arguments we should pass to find_or_create_alternate() etc.?
>
> Thanks,
> Tom
>
> ==Issue==
>
> Within a template calling the following code, which I would expect to
> find or create an alternate media if $media exists, actually produces an
> error.
>
> ===Code called===
> my $media = $element->get_related_media;
> if($media) {
> my $thumbnail = $media->find_or_create_alternate({
> file_suffix => '_200x150',
> # et_key_name => 'alt_media_container',
> element_type => 'alt_media_container',
> user => $user,
> relate => 0,
> transformer => sub {
> shift->scale( xpixels => 200, ypixels =>150 );
> },
> });
>
> ===Error this code gives===
> Can't locate object method "get_fixed_url" via package
> "alt_media_container" (perhaps you forgot to load
> "alt_media_container"?) at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2518,
> <GEN10> line 1585.
>
> ===Alternative error===
> Uncommenting et_key_name perhaps more disturbingly gives:
>
> DBD::Pg::st execute failed: ERROR: null value in column
> "primary_oc__id" violates not-null constraint
> [.for Statement "INSERT INTO media_instance (id, name, description,
> media__id, usr__id, version, media_type__id, primary_oc__id,
> category__id, file_size, file_name, location, uri, cover_date, note,
> checked_out) VALUES (NEXTVAL('seq_media_instance'), ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?)" with ParamValues: 2='Thumbnail for ',
> 3='13941', 4='1926', 5='0', 6='60'] at
> /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1138, <GEN15> line 1585.
>
> Stack:
> [/home/newint/bricolage2/lib/Bric/Util/DBI.pm:1138]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:2175]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm:1889]
> [/home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm:614]
>
> [/home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc:257]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
> [/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm:550]
> [/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:104]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:157]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm:936]
> [/home/newint/bricolage2/data/burn/comp/oc_1/autohandler:141]
> [/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
>
> Error Details (hide)
>
> Fault Class
> Bric::Util::Fault::Exception::DA
> Description
> Data Access Exception
> Timestamp
> 2012-05-11 08:42:22.000000
> Package
> Bric::Util::DBI
> Filename
> /home/newint/bricolage2/lib/Bric/Util/DBI.pm
> Line
> 1139
>
> Stack:
>
> Trace begun at /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1139
> Bric::Util::DBI::execute('DBI::st=HASH(0x5b672e0)', 'Thumbnail for
> st_alphageek_f.jpg', 'Thumbnail for ', 13941, 1926, 0, 60, undef, 1651,
> undef, undef, undef, undef, '2012-05-11 15:13:00.000000', undef, 1)
> called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
> line 2175
> Bric::Biz::Asset::Business::Media::_insert_instance('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
> called at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm
> line 1889
> eval {...} at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media.pm line 1857
> Bric::Biz::Asset::Business::Media::save('Bric::Biz::Asset::Business::Media::Image=HASH(0x5b685d0)')
> called at
> /home/newint/bricolage2/lib/Bric/Biz/Asset/Business/Media/Image.pm line 614
> Bric::Biz::Asset::Business::Media::Image::find_or_create_alternate('Bric::Biz::Asset::Business::Media::Image=HASH(0x5787250)',
> 'HASH(0x5b66f80)') called at
> /home/newint/bricolage2/data/burn/sandbox/user_1926/oc_1/blog_post.mc
> line 257
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c94290)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
> HTML::Mason::Request::call_next('HTML::Mason::Request=HASH(0x5c8af40)')
> called at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 550
> Bric::Util::Burner::Mason::chain_next('Bric::Util::Burner::Mason=HASH(0x5a81040)')
> called at /home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 104
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 157
> HTML::Mason::Component::run_dynamic_sub('HTML::Mason::Component::FileBased=HASH(0x5c99180)',
> 'main') called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 936
> HTML::Mason::Request::call_dynamic('HTML::Mason::Request=HASH(0x5c8af40)',
> 'main') called at
> /home/newint/bricolage2/data/burn/comp/oc_1/autohandler line 141
> Bric::Util::Burner::Commands::__ANON__ at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x5c99180)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 425
> HTML::Mason::Request::exec('HTML::Mason::Request=HASH(0x5c8af40)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Interp.pm line 342
> HTML::Mason::Interp::exec(undef, undef) called at
> /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
> eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm line 261
> Bric::Util::Burner::Mason::burn_one('Bric::Util::Burner::Mason=HASH(0x5a81040)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
> 'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
> 'Bric::Biz::Category=HASH(0x5c89040)') called at
> /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1585
> Bric::Util::Burner::burn_one('Bric::Util::Burner=HASH(0x5a7fee0)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)',
> 'Bric::Biz::OutputChannel=HASH(0x5c8bcd0)',
> 'Bric::Biz::Category=HASH(0x5c89040)') called at
> /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 1022
> eval {...} at /home/newint/bricolage2/lib/Bric/Util/Burner.pm line 974
> Bric::Util::Burner::preview('Bric::Util::Burner=HASH(0x5a7fee0)',
> 'Bric::Biz::Asset::Business::Story=HASH(0x55256b0)', 'story', 1926,
> undef) called at
> /home/newint/bricolage2/lib/Bric/App/Callback/Publish.pm line 117
> Bric::App::Callback::Publish::preview('Bric::App::Callback::Publish=HASH(0x19baa10)')
> called at /home/newint/bricolage2/comp/workflow/profile/preview/dhandler
> line 32
> HTML::Mason::Commands::__ANON__('checkout', 1, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x3decdf0)',
> 'checkout', 1, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1284
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1,
> 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 943
> HTML::Mason::Request::call_next('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)',
> 'checkout', 1) called at /home/newint/bricolage2/comp/autohandler line 7
> HTML::Mason::Commands::__ANON__('checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm line 135
> HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x558b940)',
> 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 1279
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 1274
> HTML::Mason::Request::comp(undef, undef, undef, 'checkout', 1) called at
> /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 473
> eval {...} at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/Request.pm
> line 425
> HTML::Mason::Request::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
> line 168
> HTML::Mason::Request::ApacheHandler::exec('HTML::Mason::Request::ApacheHandler=HASH(0x5525020)')
> called at /usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/ApacheHandler.pm
> line 825
> HTML::Mason::ApacheHandler::handle_request('HTML::Mason::ApacheHandler=HASH(0x5372040)',
> 'Apache=SCALAR(0x5a7fc80)') called at
> /home/newint/bricolage2/lib/Bric/App/Handler.pm line 307
> eval {...} at /home/newint/bricolage2/lib/Bric/App/Handler.pm line 296
> Bric::App::Handler::handler('Apache=SCALAR(0x5a7fc80)') called at
> PerlHandler subroutine `Bric::App::Handler::handler' line 1
> eval {...} at PerlHandler subroutine `Bric::App::Handler::handler' line 1
> ==