[jifty-devel] validator and filter order
Alex Vandiver
alexmv at bestpractical.com
Fri Jan 5 15:03:33 EST 2007
On Wed, 2007-01-03 at 20:12 +0000, John Green wrote:
> Using the admin mode this worked fine when creating a new record, but
> fails when I try to save a record I have edited. It appears to be
> calling the validator after the filter has been applied.
>
> Is this the intended behaviour (if it is, the difference between the
> create and update behaviour seems wrong)?
No, you're going about this the right way. Instrumenting all of the
various hooks, we seem to be doing validation at different times. Jesse
is conflating filters and canonicalization, which are two different
things. The following is the log from creating and then editing a
one-column model using the admin UI:
Create (value is "New value")
Canonicalizing 'New value' in model
Canonicalized value is 'canon New value' in model
Checking if 'canon New value' is valid in model
Canonicalizing 'canon New value' in model
Canonicalized value is 'canon canon New value' in model
Checking if 'canon canon New value' is valid in model
Before create for 'canon canon New value' in model
Encoding value 'canon canon New value' in filter
Encoded value is 'encoded canon canon New value' in filter
After create in model
Decoding value 'encoded canon canon New value' in filter
Decoded value is 'canon canon New value' in filter
Decoding value 'encoded canon canon New value' in filter
Decoded value is 'canon canon New value' in filter
Update (value is "Updated thing")
Decoding value 'encoded canon canon New value' in filter
Decoded value is 'canon canon New value' in filter
Canonicalizing 'Updated thing' in model
Canonicalized value is 'canon Updated thing' in model
Checking if 'canon Updated thing' is valid in model
Before set for 'canon Updated thing' in model
Encoding value 'canon Updated thing' in filter
Encoded value is 'encoded canon Updated thing' in filter
Checking if 'encoded canon Updated thing' is valid in model
Decoding value 'encoded canon Updated thing' in filter
Decoded value is 'canon Updated thing' in filter
After set for 'canon Updated thing' in model
Decoding value 'encoded canon Updated thing' in filter
Decoded value is 'canon Updated thing' in filter
A couple things from this: First, we're canonicalizing twice on create,
which is wasteful, but not terribly wrong (canonicalizing the canonical
form should be a no-op -- it isn't here, for demonstration purposes).
The phases there are Canonicalize, Validate, before_create, Encode, as
they should be. In the Update, we Canonicalize, Validate, before_set,
Encode, and then *validate again*, which I think is wrong.
The first validate in the update is done by Jifty::Action::Record, the
second is by __set. The answer may be that you want an action-level
_validate (which overrides model-level validation) but it still seems
wrong that validation in Jifty::DBI is happening after encoding.
Encoding should be the last step before it hits the database.
- Alex
More information about the jifty-devel
mailing list