[storm] Size Validation

James Henstridge james at jamesh.id.au
Mon Jul 7 04:42:45 BST 2008


On Mon, Jul 7, 2008 at 11:39 AM, James Henstridge <james at jamesh.id.au> wrote:
> On Sun, Jul 6, 2008 at 11:30 PM, Gerdus van Zyl <gerdusvanzyl at gmail.com> wrote:
>> Hi,
>>
>> Is there any already built in method in storm to specify the size of a
>> varchar ? eg. varchar(25) that throws an exception if the string is
>> more than 25 chars long. On a similar note: you can currently prevent
>> the use of None for notnull columns using allow_none=False; is there
>> something that prevent an empty string?
>
> If you are using the latest trunk version of Storm (not the 0.12
> tarball release), you could define a validator to do this:

Pressed send accidentally.  The example was:


  def validate_length(obj, attr_name, value):
      if value is not None and len(value) > 25:
          raise StringToLongError(...)
      return value

Then you can define your column with:

  col = Unicode(validator=validate_length)

The validator will be called when you try to assign a value to the
column, but not when reading values from the database or assigning
"lazy" values to the column.

James.



More information about the storm mailing list