37 messages in net.sourceforge.lists.plone-developersRe: CMFFormController should abort th...
FromSent OnAttachments
Dorneles TreméaNov 9, 2007 3:17 pm 
Philipp von WeitershausenNov 10, 2007 7:07 am 
Dorneles TreméaNov 10, 2007 7:58 am 
Wichert AkkermanNov 10, 2007 12:22 pm 
Martin AspeliNov 10, 2007 2:12 pm 
Wichert AkkermanNov 10, 2007 4:20 pm 
Philipp von WeitershausenNov 11, 2007 1:32 am 
Dorneles TreméaNov 11, 2007 5:19 pm 
Alan RunyanNov 11, 2007 5:20 pm 
Martin AspeliNov 11, 2007 5:44 pm 
Martin AspeliNov 11, 2007 5:51 pm 
Wichert AkkermanNov 12, 2007 4:37 am 
Sidnei da SilvaNov 12, 2007 4:43 am 
Daniel KraftNov 12, 2007 5:40 am 
Martin AspeliNov 12, 2007 5:52 am 
Dorneles TreméaNov 12, 2007 9:35 am 
Wichert AkkermanNov 12, 2007 9:56 am 
Martin AspeliNov 12, 2007 9:59 am 
Martin AspeliNov 12, 2007 10:00 am 
Dorneles TreméaNov 12, 2007 10:56 am 
Martin AspeliNov 12, 2007 11:14 am 
Martin AspeliNov 12, 2007 11:21 am 
Wichert AkkermanNov 12, 2007 11:36 am 
Martin AspeliNov 12, 2007 11:41 am 
Sidnei da SilvaNov 12, 2007 11:47 am 
Martin AspeliNov 12, 2007 12:04 pm 
Dorneles TreméaNov 12, 2007 12:28 pm 
Dorneles TreméaNov 12, 2007 12:34 pm 
Dorneles TreméaNov 12, 2007 1:29 pm 
Wichert AkkermanNov 12, 2007 1:32 pm 
Martin AspeliNov 12, 2007 1:41 pm 
Dorneles TreméaNov 12, 2007 1:44 pm 
Martin AspeliNov 12, 2007 1:46 pm 
Wichert AkkermanNov 12, 2007 1:46 pm 
Martin AspeliNov 12, 2007 1:47 pm 
Dorneles TreméaNov 12, 2007 5:11 pm 
Daniel NouriNov 13, 2007 4:14 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: CMFFormController should abort the current transaction when the validation failsActions...
From:Dorneles Treméa (deo-@public.gmane.org)
Date:Nov 12, 2007 9:35:58 am
List:net.sourceforge.lists.plone-developers

Hey Martin,

No, I mean, it's a (serious, but discoverable) bug in the code that's using CMFFormController.

In now way is this a bug in CMFFormController. At best it's a missing feature, and I'd argue it'd be a mis-feature.

I see you point, but I disagree, keep reading... ;-)

Rolling back the transaction seems drastic. In some cases, you may even want to save something even if validation fails.

If you need to save something even if the validation fails at a later point, you can do a full commit at anytime.

Doing a full premature commit is bad. Something later (outside the control of your cpy script) could fail, in which case you do want something rolled back.

You asked for a way to 'save something even if validation fails'. I presented that to you.

A premature commit is bad, but at least you have the choice to do it, and this choice is something that we don't have now for the 'abort' case.

I don't think it's hard. Let's say you set up a chain like this:

+---(success)-->[save script] --[page template]-->[validator]--+ +---(failure)-->[abort/error page]

The validator is in the chain explicitly. You may not know what in the validator exactly failed, but you *do* know that something failed, and you can react accordingly.

Of course I can do whatever I want in a custom content-type and/or plain form validation... but I'm talking about the *standard* behavior of the Archetypes/CMFFormController integration... and even further, the standard behavior of CMFFormController validation.

As Wichert and Sidnei pointed out, the default use case should be:

- abort any persistent change, and give the option to save something even if the validation fails

But the current default implementation can be read as:

- keep the persistent changes, and doesn't allow us to abort them if the validation fails... :-/

In other words: make the more sensical case be the default one, while still allowing the exception case possible.

Do you see my point?

If that's what this is all about, the Archetypes base_edit chains (which are insane), then that's an issue we should fix there, not something we should steamroll into CMFFormController just because that's easier.

I never said it was easier to fix this on CMFFormController... :-)

In fact, it's much easier to fix it directly on Archetypes, but what I want to make sure people understand is that the current implementation assumes the wrong case as the default one.

Rolling back everything if validation fails is what the vast majority wants per default.

FYI, the fix on Archetypes would be something along these lines:

Index: Archetypes/skins/archetypes/validate_base.vpy =================================================================== --- Archetypes/skins/archetypes/validate_base.vpy (revision 8902) +++ Archetypes/skins/archetypes/validate_base.vpy (working copy) @@ -18,6 +18,7 @@ if errors: message = _(u'Please correct the indicated errors.') addStatusMessage(request, message, type='error') + import transaction; transaction.abort() return state.set(status='failure', errors=errors) else: message = _(u'Changes saved.')

(We're not allowed to import the transaction module by default, but we can easily make it work as we need...)

My particular use case is the following:

- There's an AT content-type, and its schema has a reference field

- This field uses a special widget (UploadReferenceWidget) that allows you upload a file, creating a new File in ZODB *and* reference that File after its creation

- What happens now is that when the validation of any other field fails, I have no chance to abort the creation of that File

You could have an on-failed validator that did an explicit rollback?

Of course, that chain is not sane. There should be a pre-write validator that checks the whole Archetype, and only then should something be saved. In fact, I thought that's how it worked for other fields. Perhaps it's a deficiency in this particular widget's implementation?

Perhaps, but this should not block us from doing the Right Thing™!

In fact, I would say that Archetypes misses a 'Validation Failed' event... but that's story for another mail... :-)

I'm talking specifically about ZODB here, but the same would apply for RDB and file system changes. Again, if the validation fails, I would expect that *no* persistent changes remains.

I'm not sure that's a valid expectation 100% of the time, for all kinds of validators, for all use cases where CMFFormController is currently used. See my reply to Alan as well.

I agree with you that this expectation is not valid 100% of the time, but I'm sure you agree with me that it should be the default one.

Being the default one, and allowing the case where you can save things even if validation fails should covers 100% of the cases... ;-)

The fix could be done in Archetypes, but 'form processing' is a more general concept, and thus I would say that CMFFormController is the best place to do it.

I disagree. This is a case of AT not using the form controller correctly, or of your widget making wrong assumptions. In either case, something as drastic as a full transaction abort belongs there not in a general (and stable/old) framework.

[...]

Think of it differently - you don't get a transaction abort if a formlib validator or zope.interface invariant fails. That'd be crazy too. ;)

Do you still think that way now? :-)

--

_______________________________________________________

Dorneles Treméa · Developer, Jarn · www.jarn.com

Plone Solutions, Development, Hosting and Support

_______________________________________________________

Plone Solutions is now known as Jarn www.jarn.com/name-change