@@ -346,6 +346,7 @@ def _root(
346
346
< txmax
347
347
)
348
348
349
+ # NB: only apply filters to the root node
349
350
if node ._filters :
350
351
node ._subquery = node ._subquery .where (sa .and_ (* node ._filters ))
351
352
node ._subquery = node ._subquery .alias ()
@@ -420,11 +421,6 @@ def _children(self, node: Node) -> None:
420
421
421
422
if child ._filters :
422
423
423
- self .isouter = not any (
424
- column in child .table_columns
425
- for column in child .relationship .foreign_key .parent
426
- )
427
-
428
424
for _filter in child ._filters :
429
425
if isinstance (_filter , sa .sql .elements .BinaryExpression ):
430
426
for column in _filter ._orig :
@@ -575,11 +571,6 @@ def _through(self, node: Node) -> None: # noqa: C901
575
571
576
572
if child ._filters :
577
573
578
- self .isouter = not any (
579
- column in child .table_columns
580
- for column in child .relationship .foreign_key .parent
581
- )
582
-
583
574
for _filter in child ._filters :
584
575
if isinstance (_filter , sa .sql .elements .BinaryExpression ):
585
576
for column in _filter ._orig :
@@ -698,12 +689,6 @@ def _through(self, node: Node) -> None: # noqa: C901
698
689
== through .model .c [right_foreign_keys [i ]]
699
690
)
700
691
701
- if node ._filters :
702
- self .isouter = not any (
703
- column in node .table_columns
704
- for column in node .relationship .foreign_key .parent
705
- )
706
-
707
692
op = sa .and_
708
693
if node .table == node .parent .table :
709
694
op = sa .or_
@@ -715,8 +700,10 @@ def _through(self, node: Node) -> None: # noqa: C901
715
700
)
716
701
717
702
node ._subquery = inner_subquery .select_from (from_obj )
718
- if node ._filters :
719
- node ._subquery = node ._subquery .where (sa .and_ (* node ._filters ))
703
+
704
+ # NB do not apply filters to the child node as they are applied to the parent
705
+ # if node._filters:
706
+ # node._subquery = node._subquery.where(sa.and_(*node._filters))
720
707
721
708
node ._subquery = node ._subquery .group_by (
722
709
* [through .model .c [column ] for column in foreign_keys [through .name ]]
@@ -759,13 +746,6 @@ def _non_through(self, node: Node) -> None: # noqa: C901
759
746
760
747
if child ._filters :
761
748
762
- # NB:sometimes the FK is in the parent not the child
763
- # if none of child.relationship.foreign_key.parent is in child.table_columns then isouter = True
764
- self .isouter = not any (
765
- column in child .table_columns
766
- for column in child .relationship .foreign_key .parent
767
- )
768
-
769
749
for _filter in child ._filters :
770
750
if isinstance (_filter , sa .sql .elements .BinaryExpression ):
771
751
for column in _filter ._orig :
@@ -882,8 +862,9 @@ def _non_through(self, node: Node) -> None: # noqa: C901
882
862
)
883
863
node ._subquery = node ._subquery .where (sa .and_ (* where ))
884
864
885
- if node ._filters :
886
- node ._subquery = node ._subquery .where (sa .and_ (* node ._filters ))
865
+ # NB do not apply filters to the child node as they are applied to the parent
866
+ # if node._filters:
867
+ # node._subquery = node._subquery.where(sa.and_(*node._filters))
887
868
888
869
if node .relationship .type == ONE_TO_MANY :
889
870
node ._subquery = node ._subquery .group_by (
0 commit comments