[Dancer-users] trouble with sessions

Mr. Puneet Kishor punk.kish at gmail.com
Fri Mar 25 04:51:49 CET 2011


Suddenly, out of the blue today, my web site is broken because of sessions problem. I have been using Dancer::Sessions::SQLite, something that I had coded, and that had worked just fine for months until today. Today I start getting the following error

{
   "error" : "DBD::SQLite::st execute failed: constraint failed\nsessions.id may not be NULL at /usr/local/lib/perl5/site_perl/5.12.1/Dancer/Session/SQLite.pm line 159.\n"
}

The offending line is

142> sub flush {
143>     my $self = shift;
144> 
145>     my $sth;
146>     if (session_db($self->id)) {
147>     	$sth = $dbh->prepare(qq{
148>         	UPDATE sessions 
149>         	SET a_session = ? 
150>         	WHERE id = ?
151> 	    });
152>     }
153>     else {
154> 		$sth = $dbh->prepare(qq{
155> 	    	INSERT INTO sessions (a_session, id) 
156> 	    	VALUES (?, ?)
157> 	    });
158>     }
159>     $sth->execute(Storable::freeze($self), $self->id);
160>     
161>     return $self;
162> }

Seems like $self->id is not generating a session id. So, while I try and figure out what is going on, I thought I would switch to the factory-provided Dancer::Session::Storable. However, with that I get the following error

{
   "error" : "Warning caught during route execution: Use of uninitialized value $id in concatenation (.) or string at /usr/local/lib/perl5/site_perl/5.12.1/Dancer/Session/Storable.pm line 57.\n"
}

The offending line is

55> sub session_file {
56>     my ($id) = @_;
57>     return path(setting('session_dir'), "session_$id.stor");
58> }

Hmmmm... once again, no $id.

So, what is going on, and how do I fix this? The only thing new that I can think is that I upgraded to Dancer 1.3020 a couple of days ago. Although, I could have sworn that the web site was working fine even after upgrading, but I guess I should swear.

Any help would be much appreciated.. this is a tight spot.

Puneet.


More information about the Dancer-users mailing list