From e36dd6b6334c20617ed09916b73cf82e3862f4db Mon Sep 17 00:00:00 2001 From: Dmytro Kazanzhy Date: Thu, 3 Feb 2022 22:45:33 +0200 Subject: [PATCH 1/2] Fixed issue #20007 --- .../google/cloud/transfers/postgres_to_gcs.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/airflow/providers/google/cloud/transfers/postgres_to_gcs.py b/airflow/providers/google/cloud/transfers/postgres_to_gcs.py index d7c777757c33c..875bbde8d2054 100644 --- a/airflow/providers/google/cloud/transfers/postgres_to_gcs.py +++ b/airflow/providers/google/cloud/transfers/postgres_to_gcs.py @@ -41,26 +41,22 @@ class _PostgresServerSideCursorDecorator: def __init__(self, cursor): self.cursor = cursor - self.rows = [] self.initialized = False def __iter__(self): return self def __next__(self): - if self.rows: - return self.rows.pop() - else: - self.initialized = True - return next(self.cursor) + self.initialized = True + return next(self.cursor) @property def description(self): - """Fetch first row to initialize cursor description when using server side cursor.""" + """Fetch a row to initialize cursor's `description` attribute when server side cursor is used.""" if not self.initialized: - element = self.cursor.fetchone() - self.rows.append(element) self.initialized = True + self.cursor.fetchone() + self.cursor.scroll(0, mode='absolute') return self.cursor.description From ad1d827b0d23733f3af1944590c8f32dbba156a0 Mon Sep 17 00:00:00 2001 From: Dmytro Kazanzhy Date: Fri, 4 Feb 2022 19:36:15 +0200 Subject: [PATCH 2/2] Fixed misleading --- .../google/cloud/transfers/postgres_to_gcs.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/airflow/providers/google/cloud/transfers/postgres_to_gcs.py b/airflow/providers/google/cloud/transfers/postgres_to_gcs.py index 875bbde8d2054..c233b5c4c9758 100644 --- a/airflow/providers/google/cloud/transfers/postgres_to_gcs.py +++ b/airflow/providers/google/cloud/transfers/postgres_to_gcs.py @@ -41,22 +41,27 @@ class _PostgresServerSideCursorDecorator: def __init__(self, cursor): self.cursor = cursor + self.rows = [] self.initialized = False def __iter__(self): return self def __next__(self): - self.initialized = True - return next(self.cursor) + if self.rows: + return self.rows.pop() + else: + self.initialized = True + return next(self.cursor) @property def description(self): - """Fetch a row to initialize cursor's `description` attribute when server side cursor is used.""" + """Fetch first row to initialize cursor description when using server side cursor.""" if not self.initialized: + element = self.cursor.fetchone() + if element is not None: + self.rows.append(element) self.initialized = True - self.cursor.fetchone() - self.cursor.scroll(0, mode='absolute') return self.cursor.description