RuntimeError (no key)

24 views
Skip to first unread message

Rabindranath Bustos Martínez

unread,
Mar 2, 2012, 7:33:02 PM3/2/12
to cantango
Hello. I haven't been able to get cantango to run with my application.
It always gives me a RuntimeError (no key) exception when it loads the
permissions for a given user model, and I have no idea why is
happening, even after spending the hole day reading all the wiki pages
and trying different things.

I created a repository on github with a minimal application (almost
the same as the sample from the quickstart guide) that shows the error
I'm having:

https://github.com/rabusmar/cantangotest

Any help would be greatly appreciated.

eveevans

unread,
Mar 2, 2012, 7:36:51 PM3/2/12
to cantango
I have the same problem ..

On 2 mar, 18:33, Rabindranath Bustos Martínez <rabus...@gmail.com>
wrote:

Kristian Mandrup

unread,
Mar 3, 2012, 4:00:22 AM3/3/12
to cant...@googlegroups.com
Could you show exactly which error you get (Stack trace). I could imagine it is because it is unable to create a caching key.

Rabindranath Bustos Martínez

unread,
Mar 3, 2012, 9:58:12 AM3/3/12
to cant...@googlegroups.com
Here is the full stack trace:  http://pastebin.com/YpSvEDeD
--
Rabindranath

Kristian Mandrup

unread,
Mar 3, 2012, 12:39:50 PM3/3/12
to cant...@googlegroups.com
Hmm, I don't recall ever seeing that error before. I think it is caused when CanTango tries to access the session cache (invalidate it), and for some reason when it tries to determine the Session key to use, the key returns nil, hence "no key". If the User model has an #email method or you configure the key specifically, and the particular User object returns a non-nil value for the key method, it should work?

If you still have problems, I recommend that you try out the cantango-permits project instead. This is part of a complete reimplementation of cantango, where I split the project into multiple smaller projects that have much better test coverage, better design and works! The 0.9.4+ of the original was developed a bit too hastily in the end without proper testing unfortunately. I have since pretty much abandoned the master branch. 

Let me know if cantango-permits works better for you or if you still run into some trouble. Good luck!

Kristian

PS: I plan to soon work some more on the finishing touches for a 1.0 release of the complete rewrite. I still need some work on cantango-permit_store. Any help appreciated!

Rabindranath Bustos Martínez

unread,
Mar 3, 2012, 9:07:46 PM3/3/12
to cant...@googlegroups.com
Hi Kristian,

Thanks for your response. As you can see in the minimal repository I set up, the user model is just a standard devise user, so it does have a non-null email field. I also wasn't able to successfully use cantango-permits with my project, it gave me a several errors, probably because of my inexperience in configuring the right environment for it, since it now seems that cantango is spread across several different gems, and I couldn't find any information in setting them up the right way. I also tried with cantango branches major-refactor and cantango-1x, and even reverting to version 0.8.9.5, but everything failed in different ways. Maybe a you could give me some hint so I can use the cantango-permits project, I admit not having any experience in using experimental gems before, since I've been into ruby & rails for a couple of months only.

Anyway, as you noted that the problem was probably due to caching, I ended using up version 0.9.4.7 again and turned caching off by setting config.ability.mode = :no_cache as a temporary measure while I find the proper solution. After that I had to implement the patch shown in another thread, since it gave me the same error, and I also had to add a dummy parameter to the roles_list because it seems that sometimes it is called with a role name parameter, like it thinks it is calling has_role? or something. I also added a temporary user permit to execute rules of the permissions.yml file, since it seems that the permissions engine depends on cache being turned on (could you confirm that this is the case, or is it possible to use the permissions engine in no_cache mode?).

After all that it seems the abilities are being executed fine, however now I'm running with another issue: when a page is requested it seems that the permits are being registered over and over again like 50 times or so, resulting in very slow page response times. When I turn debugging on, this is the the output I get for a single page request where I make a single usuario_can? call (this is the backtrace of all those messages - I have registered 2 permit clases, an user permit to simulate the permissions engine and a test role permit). Have you seen anything similar before?

I know you should be pretty busy with the refactoring right now, but I would highly appreciate any help on the subject.

Best regards,

Rabindranath
--
Rabindranath

Kristian Mandrup

unread,
Mar 4, 2012, 5:58:25 AM3/4/12
to cant...@googlegroups.com
Hmm, very interesting. Haven't seen this registration bug before. CanTango by default automatically registers a Permit whenever the class file is loaded into memory and the Permit inheritance hook is executed. Not sure why Rails would continually load the same model files (autoload) and execute such hooks on each request. One fix is to find where the Registration is performed (CanTango::RolePermit fx) and only perform registration if permit is not already registered. Alternatively, disable autoloading of Permits (remove from autoload folder) and load them once, "manually", fx by finding all the permits in a permits folder and forcing ruby to load them - fx in cantango initializer.
Reply all
Reply to author
Forward
0 new messages