[Cubicweb] ValidationError and implicit rollbacks

Aurélien Campeas aurelien.campeas at logilab.fr
Thu Sep 30 16:06:50 CEST 2010

Le jeudi 30 septembre 2010 à 15:57 +0200, Adrien Di Mascio a écrit :
> Hi there,


> In CW 3.9, if a ValidationError is raised, the transaction is implicitly 
> rollbacked. As far as I understand, this is done to prevent any later 
> commit() (in the same transaction) from letting the database in an 
> inconsistent state.

hmm, it used to be that the commit/rollback, from the web front pov, was
done in application.publish (or something)

that is quite predictable & allows various ValidationError handling from

am i missing something ?

> I've just discovered a strange side-effect which is that a given eid can 
> be assigned twice in the same HTTP request processing. The following 
> simple set of instructions illustrates this behaviour :
>      def test_validation_error_behaviour(self):
>          create = self.request().create_entity
>          user1 = create('CWUser', login=u'foo', upassword=u'foo')
>          try:
>              user2 = create('CWUser', login=u'foo', upassword=u'foo')
>          except ValidationError:
>              # a ValidationError is raised because logins are unique
>              pass
>          user3 = create('CWUser', login=u'bar', upassword=u'bar')
>          # The following assertion fails and user1 doesn't event exist
>          # anymore
>          self.assertNotEqual(user1.eid, user3.eid)

this used to happen already when uncarefully handling things like

self.assertRaises(ValidationError, self.commit)

(I believe)

> For the record, I've discovered this because I implemented a custom 
> EditController that catches ValidationError and is able to treat some of 
> them as part of the normal execution flow under certain conditions.
> This post is here to inform some of you who, just like me, might have 
> skipped this new "feature". I wonder however if I hadn't prefered simply
> a non-commitable transaction (i.e. waiting for an explicit rollback()) 
> rather than an implicit one.
> What do you think ?

Immediately & automatically (behind-our-back) rollbacking on
ValidationError is wrong (I think it breaks working customer code).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Ceci est une partie de message numériquement signée
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20100930/3835a028/attachment-0272.sig>

More information about the Cubicweb mailing list