Skip to content

Commit d2b8ecd

Browse files
committed
fib bug not tracking through table on insert and filtering on inner qubquery
1 parent 3ba10a3 commit d2b8ecd

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

pgsync/querybuilder.py

+8-27
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def _root(
346346
< txmax
347347
)
348348

349+
# NB: only apply filters to the root node
349350
if node._filters:
350351
node._subquery = node._subquery.where(sa.and_(*node._filters))
351352
node._subquery = node._subquery.alias()
@@ -420,11 +421,6 @@ def _children(self, node: Node) -> None:
420421

421422
if child._filters:
422423

423-
self.isouter = not any(
424-
column in child.table_columns
425-
for column in child.relationship.foreign_key.parent
426-
)
427-
428424
for _filter in child._filters:
429425
if isinstance(_filter, sa.sql.elements.BinaryExpression):
430426
for column in _filter._orig:
@@ -575,11 +571,6 @@ def _through(self, node: Node) -> None: # noqa: C901
575571

576572
if child._filters:
577573

578-
self.isouter = not any(
579-
column in child.table_columns
580-
for column in child.relationship.foreign_key.parent
581-
)
582-
583574
for _filter in child._filters:
584575
if isinstance(_filter, sa.sql.elements.BinaryExpression):
585576
for column in _filter._orig:
@@ -698,12 +689,6 @@ def _through(self, node: Node) -> None: # noqa: C901
698689
== through.model.c[right_foreign_keys[i]]
699690
)
700691

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-
707692
op = sa.and_
708693
if node.table == node.parent.table:
709694
op = sa.or_
@@ -715,8 +700,10 @@ def _through(self, node: Node) -> None: # noqa: C901
715700
)
716701

717702
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))
720707

721708
node._subquery = node._subquery.group_by(
722709
*[through.model.c[column] for column in foreign_keys[through.name]]
@@ -759,13 +746,6 @@ def _non_through(self, node: Node) -> None: # noqa: C901
759746

760747
if child._filters:
761748

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-
769749
for _filter in child._filters:
770750
if isinstance(_filter, sa.sql.elements.BinaryExpression):
771751
for column in _filter._orig:
@@ -882,8 +862,9 @@ def _non_through(self, node: Node) -> None: # noqa: C901
882862
)
883863
node._subquery = node._subquery.where(sa.and_(*where))
884864

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))
887868

888869
if node.relationship.type == ONE_TO_MANY:
889870
node._subquery = node._subquery.group_by(

pgsync/sync.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,10 @@ def _insert_op(
577577
node, payload, foreign_keys, _filters
578578
)
579579

580-
# through table with a direct references to root
581-
if not _filters:
582-
_filters = self._through_node_resolver(
583-
node, payload, _filters
584-
)
580+
# also check through table with a direct references to root
581+
_filters = self._through_node_resolver(
582+
node, payload, _filters
583+
)
585584

586585
if _filters:
587586
filters[self.tree.root.table].extend(_filters)

requirements/base.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#
77
async-timeout==5.0.1
88
# via redis
9-
boto3==1.35.75
9+
boto3==1.35.76
1010
# via -r requirements/base.in
11-
botocore==1.35.75
11+
botocore==1.35.76
1212
# via
1313
# boto3
1414
# s3transfer
@@ -63,7 +63,7 @@ python-dotenv==1.0.1
6363
# via
6464
# -r requirements/base.in
6565
# environs
66-
redis==5.2.0
66+
redis==5.2.1
6767
# via -r requirements/base.in
6868
requests==2.32.3
6969
# via

requirements/dev.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ async-timeout==5.0.1
88
# via redis
99
black==24.10.0
1010
# via -r requirements/dev.in
11-
boto3==1.35.75
11+
boto3==1.35.76
1212
# via -r /Users/tolu/pgsync/requirements/base.in
13-
botocore==1.35.75
13+
botocore==1.35.76
1414
# via
1515
# boto3
1616
# s3transfer
@@ -27,7 +27,7 @@ click==8.1.7
2727
# via
2828
# -r /Users/tolu/pgsync/requirements/base.in
2929
# black
30-
coverage[toml]==7.6.8
30+
coverage[toml]==7.6.9
3131
# via
3232
# -r requirements/dev.in
3333
# pytest-cov
@@ -129,7 +129,7 @@ python-dotenv==1.0.1
129129
# environs
130130
pyyaml==6.0.2
131131
# via pre-commit
132-
redis==5.2.0
132+
redis==5.2.1
133133
# via -r /Users/tolu/pgsync/requirements/base.in
134134
requests==2.32.3
135135
# via

0 commit comments

Comments
 (0)