[Twisted-web] freeform and adbapi

Tommi Virtanen tv at twistedmatrix.com
Sat Apr 16 10:22:28 MDT 2005

Stephan Cieszynski wrote:
> class Username(annotate.Typed):
>     def coerce (self, val, configurable):
>         d = dbpool.runQuery("""SELECT username FROM userdb WHERE 
> username = %s""", str(val))
>         d.addCallback(_cb, val)
>         d.addErrback(_eb)
>         return d

coerce cannot defer. To do that, move your validation into e.g. the
start of an autocallable and do something like

def foo(self, ctx, foo, bar):
     if not valid(foo):
         raise annotate.ValidateError(
             {'foo': 'Foo is bad.' },
foo = annotate.autocallable(foo)

where the dict is variablename->errormessage. See ValidateError for

More information about the Twisted-web mailing list