_rollback() work if failure occurs in these calls.
This is the location where there was unbalanced _beginWork()/_commit() calls. In future, when writing tests, it's probably good to check this often in the tests.
This commit is contained in:
		
							parent
							
								
									794d34a79f
								
							
						
					
					
						commit
						096561a5c4
					
				
					 1 changed files with 11 additions and 5 deletions
				
			
		|  | @ -744,17 +744,23 @@ sub addRequest($$) { | |||
|     unless $self->_verifyId($supporterId); | ||||
| 
 | ||||
|   $self->_beginWork; | ||||
|   $self->_getOrCreateRequestType($params); | ||||
|   $self->_getOrCreateRequestConfiguration($params) if (defined $params->{requestConfiguration} or | ||||
|                                                        defined $params->{requestConfigurationId}); | ||||
|   eval { | ||||
|     $self->_getOrCreateRequestType($params); | ||||
|     $self->_getOrCreateRequestConfiguration($params) if (defined $params->{requestConfiguration} or | ||||
|                                                         defined $params->{requestConfigurationId}); | ||||
|   }; | ||||
|   if ($@ or not defined $params->{requestTypeId}) { | ||||
|     my $err = $@; | ||||
|     $err = "addRequest: unable to create requestType"  if (not defined $err); | ||||
|     $self->_rollback(); | ||||
|     die $@ if $@; | ||||
|   } | ||||
| 
 | ||||
|   # After those two calls above, I know I have requestTypeId and | ||||
|   # requestConfigurationId are accurate.  Note that | ||||
|   # $params->{requestConfigurationId} can be undef, which is permitted in the | ||||
|   # database schema. | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|   my $sth = $self->dbh->prepare("INSERT INTO request(supporter_id, request_type_id, request_configuration_id, notes, date_requested) " . | ||||
|                                              "VALUES(?,            ?,               ?,                        ?,      date('now'))"); | ||||
|   $sth->execute($supporterId, $params->{requestTypeId}, $params->{requestConfigurationId}, $params->{notes}); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn