diff --git a/product/ERP5Type/patches/sqltest.py b/product/ERP5Type/patches/sqltest.py
index f0fb665fad3df2e964d86c048bebd362598117cc..43e468fd5fe1686c6b838477301c958814c538b3 100644
--- a/product/ERP5Type/patches/sqltest.py
+++ b/product/ERP5Type/patches/sqltest.py
@@ -28,7 +28,7 @@ if 1: # For easy diff with original
                 v=md[expr]
             else:
                 v=expr(md)
-        except KeyError:
+        except (KeyError, NameError):
             if args.has_key('optional') and args['optional']:
                 return ''
             raise ValueError, 'Missing input variable, <em>%s</em>' % name