1132708 and 1132731

Addresses https://bugs.launchpad.net/openquake/+bug/1132708 and https://bugs.launchpad.net/openquake/+bug/1132731

For a clean diff, https://github.com/gem/oq-engine/pull/1057 should land first