Skip to content

Commit f7a8e01

Browse files
authored
fix: commit transaction from pandas read sql query (#1492)
1 parent 685a56b commit f7a8e01

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

sqlmesh/core/engine_adapter/postgres.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import logging
44
import typing as t
55

6+
from sqlglot import exp
7+
68
from sqlmesh.core.engine_adapter.base_postgres import BasePostgresEngineAdapter
79
from sqlmesh.core.engine_adapter.mixins import (
810
LogicalReplaceQueryMixin,
911
PandasNativeFetchDFSupportMixin,
1012
)
1113

1214
if t.TYPE_CHECKING:
13-
pass
15+
from sqlmesh.core.engine_adapter._typing import DF
1416

1517
logger = logging.getLogger(__name__)
1618

@@ -20,3 +22,16 @@ class PostgresEngineAdapter(
2022
):
2123
DIALECT = "postgres"
2224
SUPPORTS_INDEXES = True
25+
26+
def _fetch_native_df(
27+
self, query: t.Union[exp.Expression, str], quote_identifiers: bool = False
28+
) -> DF:
29+
"""
30+
`read_sql_query` when using psycopg will result on a hanging transaction that must be committed
31+
32+
https://github.com/pandas-dev/pandas/pull/42277
33+
"""
34+
df = super()._fetch_native_df(query, quote_identifiers)
35+
if not self._connection_pool.is_transaction_active:
36+
self._connection_pool.commit()
37+
return df

0 commit comments

Comments
 (0)