Skip to content

Commit

Permalink
fix UUID primary key on parent table #543
Browse files Browse the repository at this point in the history
  • Loading branch information
toluaina committed Jun 12, 2024
1 parent b554ea0 commit 0f22a46
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion pgsync/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ def __init__(self, verbose: bool = False):
self.isouter: bool = True
self._cache: dict = {}

def _eval_expression(
self, expression: sa.sql.elements.BinaryExpression
) -> sa.sql.elements.BinaryExpression:
if isinstance(
expression.left.type, sa.dialects.postgresql.UUID
) or isinstance(expression.right.type, sa.dialects.postgresql.UUID):
if not isinstance(
expression.left.type, sa.dialects.postgresql.UUID
) or not isinstance(
expression.right.type, sa.dialects.postgresql.UUID
):
# handle UUID typed expressions:
# psycopg2.errors.UndefinedFunction: operator does not exist: uuid = integer
return expression.left == None

return expression

def _build_filters(
self, filters: t.Dict[str, t.List[dict]], node: Node
) -> t.Optional[sa.sql.elements.BooleanClauseList]:
Expand All @@ -46,7 +63,11 @@ def _build_filters(
for values in filters.get(node.table):
where: t.List = []
for column, value in values.items():
where.append(node.model.c[column] == value)
where.append(
self._eval_expression(
node.model.c[column] == value
)
)
# and clause is applied for composite primary keys
clause.append(sa.and_(*where))
return sa.or_(*clause)
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#
async-timeout==4.0.3
# via redis
boto3==1.34.123
boto3==1.34.124
# via -r requirements/base.in
botocore==1.34.123
botocore==1.34.124
# via
# boto3
# s3transfer
Expand Down
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ async-timeout==4.0.3
# via redis
black==24.4.2
# via -r requirements/dev.in
boto3==1.34.123
boto3==1.34.124
# via -r requirements/base.in
botocore==1.34.123
botocore==1.34.124
# via
# boto3
# s3transfer
Expand Down

0 comments on commit 0f22a46

Please sign in to comment.