-1

Working in symfony 1.4, with Propel for my ORM (not sure how to find the version of Propel).

In a unit test of an object with a unique constraint in the database, I test for the exception being caught:

try {
  $room1a->save();
  // Shouldn't have saved, so shouldn't have an id
  $t->ok(!$room1a->getId(), "Failed to save duplicate room");
} catch (Exception $e) {
  $t->ok($e, "Threw exception on creating duplicate room");
}

but if I then correct the duplication and try again, thus

$room1a->setCode('1a');
$room1a->save();
$t->ok($room1a->getId()), "Saved this time");

I get "Unable to get sequence id":

     PropelException: Unable to get sequence id. [wrapped:                
  SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current        
  transaction is aborted, commands ignored until end of transaction    
  block]                                                               
  (in                                                                  
  lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
  on line 264)  

I've tried recreating the object (i.e. a new Room object) and saving it, with the same result; it appears that there is a state in the connection (?) which needs resetting.

The only way round I've found is to roll back the transaction and begin a new one.

Colin Fine
  • 3,334
  • 1
  • 20
  • 32

1 Answers1

0

I've found the answer: that's how transactions are supposed to work.

I'm wrapping my unit test script in a transaction so as not to change the database, and I hadn't realised that raising a constraint error would abort the transaction.

A bit annoying for me, because I'll have to start a new transaction and set up the data again, for subsequent tests.

Colin Fine
  • 3,334
  • 1
  • 20
  • 32