I've opened a ticket #7330 which resolves #5381 and #5382. The patch
includes a unit test and the fix itself.
I'd love to see this get rolled in at some point as it makes unit
testing with multiple databases possible, which is something my team
is dealing with and something others have to deal with as well if
multiple databases are used from within an application.