Fixed lp:1308146 - backported from trunk

See http://pad.lv/1308146 - this fixes the issue by backporting
the already landed fix from trunk (#786).