From 0f22a466fe7925cef2bcc3ac7c649b2eabb3f0c4 Mon Sep 17 00:00:00 2001 From: Tolu Aina <7848930+toluaina@users.noreply.github.com> Date: Wed, 12 Jun 2024 18:55:02 +0100 Subject: [PATCH] fix UUID primary key on parent table #543 --- pgsync/querybuilder.py | 23 ++++++++++++++++++++++- requirements/base.txt | 4 ++-- requirements/dev.txt | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pgsync/querybuilder.py b/pgsync/querybuilder.py index bda8b154..b32575a4 100644 --- a/pgsync/querybuilder.py +++ b/pgsync/querybuilder.py @@ -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]: @@ -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) diff --git a/requirements/base.txt b/requirements/base.txt index bc39439d..3c1c87aa 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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 diff --git a/requirements/dev.txt b/requirements/dev.txt index f33b860f..792437e2 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -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