4 5 x backport

Bug fixes included:
https://github.com/xtuple/xtuple/commit/26f8550562209b0a5aac5d3f3e851543848226a4
https://github.com/xtuple/xtuple/commit/9cdfa8dc91eeda6af715329bff7a880506e616d7