← Back to team overview

launchpad-dev team mailing list archive

Re: Parsing/validating work items

 

On Tue, Feb 21, 2012 at 2:12 PM, Guilherme Salgado
<guilherme.salgado@xxxxxxxxxx> wrote:
> And this means the parsing (which implies validating the input as well)
> will happen twice: once when the form machinery validates the input and
> again when it passes the raw input to updateWorkItems(). Since the
> parsing involves looking up objects in the DB, doing this twice is not
> ideal.

Perhaps you can cache the result of parsing in a location shared between
the form validation and updateWorkItems() and use the string (or its ID)
passed to updateWorkItems() to look up the parsed value (falling back to
parsing from scratch if none is found).

Another thought: if the form validators are allowed to return mutated
values, you can return a subclass of str that has an attribute which
stashes the parsed value.  updateWorkItems() can then check to see if
the string it is passed has an already-parsed value along for the ride.
-- 
Benji York


Follow ups

References