The issue was that if you use a where clause with an implicit join in sqlalchemy, then it does a cartesian product instead of inner join, and gives unexpected results.
Testing
updated unit test to reproduce the issue. It failed before and passes now.
The issue was that if you use a where clause with an implicit join in sqlalchemy, then it does a cartesian product instead of inner join, and gives unexpected results.
Testing
updated unit test to reproduce the issue. It failed before and passes now.