forward-port a bugfix from bug reported to substanced (Pylons/substanced#109)