[Catalyst] "Unknown column 'me.role'" error

Dustin Suchter dsuchter at ucla.edu
Fri Sep 7 07:15:26 GMT 2007


This is my first time using Catalyst and I'm hitting a problem that
I've been trying to debug for a shamefully long time now with no
success.

I started by going step-by-step through Jon Rockway's tutorial on
CPAN
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701002/lib/Catalyst/Manual/Tutorial.pod
and I ended up with exactly the final project you'd expect, working
and all.

I have made two changes to the example system and am hitting an
error I can't seem to debug:

(1) I changed the storage engine from SQLite to MySQL.

(2) I went through the code and changed the ideas of "books" and
"authors" to "campaigns" and "clients" respectively. I literally
used search-replace in Vim to do the changes, paying close attention
to plurality, capitalization, and actual path/filenames.

Now when I login to my application I get an odd error (the entire
text from the error page is at the bottom of this email). As far as
I can tell the root of the problem is that the $c->login method is
derivatively causing a problem with a JOINed SQL statement.

Here's the broken statement, taken from the error message:

###begin broken SQL###
SELECT me.role FROM users me LEFT JOIN user_roles map_user_role ON (
map_user_role.user_id = me.id ) WHERE ( map_user_role.user_id = ? )
###end broken SQL###

Keep in mind the framework's inner guts generated this SQL
automagically - I had very little to do with it. Notice how the
SELECT uses the alias table "me" and selects the column "role",
despite the fact that the column "role" only exists in the other
table, "user_roles"?

This SQL is clearly broken, as I have verified by hand it does not
produce the correct output. However, a simple modification to this:

###being fixed SQL###
SELECT role FROM users me LEFT JOIN user_roles map_user_role ON (
map_user_role.user_id = me.id ) WHERE ( map_user_role.user_id = ? )
###end fixed SQL###

Does produce the right output.

Even weirder, though, is that I seem to be logged into my
application despite landing on an error page once I hit submit. To
explain more, if I go back to the "/login" page in my URL bar from
this error page, the application clearly recognizes that I am logged
in properly. How could that be?


###full text from the error page###
Campaign List

An error has occurred. We're terribly sorry about that, but it's one
of those things that happens from time to time. Let's just hope the
developers test everything properly before release...

Here's the error message, on the off-chance that it means something
to you: undef error - DBIx::Class::ResultSet::all(): DBI Exception:
DBD::mysql::st execute failed: Unknown column 'me.role' in 'field
list' [for Statement "SELECT me.role FROM users me LEFT JOIN
user_roles map_user_role ON ( map_user_role.user_id = me.id ) WHERE
( map_user_role.user_id = ? )" with ParamValues: 0='1'] at
/usr/local/lib/perl5/site_perl/5.8.8/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
line 119
######

The overall question is, what the heck is going on?!?

Thanks to anyone who even read this far!
-d



More information about the Catalyst mailing list