backport. closes #460, #552, which were also fixed going forward by http...

...s://github.com/Pylons/pyramid/commit/95d5b72927484fa3882c5c47bf79d591a5af50a5