There is a testcase attached as well as a proposed fix. I didn't try the test case, but we see the same problem in ORM 4, specifically in 4.1.7.