I've attached a small sample program that demonstrates the problem. You can toggle working/non-working behaviour by toggling commenting on line 27.
I've tried to open a bug report, but the system isn't letting me register for Trac:
Trac detected an internal error:
KeyError: 'recaptcha_challenge_field'