Show
Ignore:
Timestamp:
07/31/07 17:26:10 (3 years ago)
Author:
eevee
Message:

Attempted fix for the duplicate key error.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee.pm

    r235 r270  
    6565 
    6666{ 
     67    # WARNING: HERE BE DRAGONS, AND BY DRAGONS I MEAN HACKS 
     68    # TODO: WHAT THE FUCK CLEAN THIS GARBAGE UP WITH PLUGINS OR SOMETHING 
     69 
    6770    no strict 'refs'; 
    6871 
     
    7376        $self->reset; 
    7477        return not $first; 
     78    }; 
     79 
     80    # DBIx::Class's find_or_create is incredibly stupid and allows for race 
     81    # conditions with critical code like this. 
     82    # This is MySQL-specific!  Also it is a horrendous hack. 
     83    # CAVEAT EMPTOR: may break if you upgrade 
     84    *{'Catalyst::Plugin::Session::Store::DBIC::Delegate::session'} = sub { 
     85        my ($self, $key) = @_; 
     86 
     87        my $row = $self->_session_row; 
     88 
     89        unless ($row) { 
     90            eval { 
     91                $row = $self->model->find_or_create({ $self->id_field => $key }); 
     92            } 
     93            if ($@ and $@ =~ /Duplicate entry/) { 
     94                $row = $self->model->create({ $self->id_field => $key }); 
     95            } else { 
     96                die $@; 
     97            } 
     98            $self->_session_row($row); 
     99        } 
     100 
     101        return $row; 
    75102    }; 
    76103}