Skip to content

Commit 8c12fc4

Browse files
StpMaxlucas-koontztino097
authored
Release 25.14.1 (#12128)
Co-authored-by: Lucas Koontz <lucas.emanuel.koontz@gmail.com> Co-authored-by: Konstantin Sivakov <konstantin.sivakov@gmail.com>
1 parent 9446130 commit 8c12fc4

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

mindsdb/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = "MindsDB"
22
__package_name__ = "mindsdb"
3-
__version__ = "25.14.0"
3+
__version__ = "25.14.1"
44
__description__ = "MindsDB's AI SQL Server enables developers to build AI tools that need access to real-time data to perform their tasks"
55
__email__ = "jorge@mindsdb.com"
66
__author__ = "MindsDB Inc"

mindsdb/integrations/handlers/postgres_handler/postgres_handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ def _make_connection_args(self):
176176
if self.connection_args.get("autocommit"):
177177
config["autocommit"] = self.connection_args.get("autocommit")
178178

179-
# If schema is not provided set public as default one
180-
if self.connection_args.get("schema"):
181-
config["options"] = f"-c search_path={self.connection_args.get('schema')},public"
182179
return config
183180

184181
@profiler.profile()
@@ -199,6 +196,12 @@ def connect(self):
199196
try:
200197
self.connection = psycopg.connect(**config)
201198
self.is_connected = True
199+
200+
schema = self.connection_args.get("schema")
201+
if schema:
202+
with self.connection.cursor() as cur:
203+
cur.execute(f'SET search_path TO "{schema}", public;')
204+
self.connection.commit()
202205
return self.connection
203206
except psycopg.Error as e:
204207
logger.error(f"Error connecting to PostgreSQL {self.database}, {e}!")

tests/unit/handlers/test_postgres.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ def test_native_query_error(self):
208208
# Ensure rollback was called
209209
mock_conn.rollback.assert_called_once()
210210

211+
def test_connect_with_schema_sets_search_path_after_connection(self):
212+
"""
213+
Tests that when schema is provided, search_path is set via SET command
214+
after connection (pooler-compatible) rather than via startup options.
215+
"""
216+
self.tearDown()
217+
self.setUp()
218+
self.handler.connection_args["schema"] = "my_schema"
219+
220+
mock_cursor = MockCursorContextManager()
221+
self.mock_connect.return_value.cursor.return_value = mock_cursor
222+
223+
connection = self.handler.connect()
224+
225+
self.assertTrue(self.handler.is_connected)
226+
self.assertIsNotNone(connection)
227+
228+
mock_cursor.execute.assert_called_once_with('SET search_path TO "my_schema", public;')
229+
self.mock_connect.return_value.commit.assert_called_once()
230+
211231
def test_make_connection_args_applies_overrides(self):
212232
handler = self.handler
213233
handler.connection_args = OrderedDict(
@@ -223,7 +243,6 @@ def test_make_connection_args_applies_overrides(self):
223243
config = handler._make_connection_args()
224244
self.assertEqual(config["application_name"], "mdb")
225245
self.assertEqual(config["connect_timeout"], 10)
226-
self.assertEqual(config["options"], "-c search_path=custom,public")
227246
self.assertTrue(config["autocommit"])
228247

229248
def test_map_type_handles_known_and_unknown(self):
@@ -536,9 +555,6 @@ def test_connection_parameters(self):
536555
self.assertEqual(call_kwargs["connect_timeout"], 10)
537556
self.assertEqual(call_kwargs["sslmode"], "prefer")
538557

539-
expected_options = "-c search_path=public,public"
540-
self.assertEqual(call_kwargs["options"], expected_options)
541-
542558
# Test with a different schema
543559
# Create a fresh handler with different schema
544560
self.tearDown()
@@ -548,8 +564,6 @@ def test_connection_parameters(self):
548564

549565
self.handler.connect()
550566
call_kwargs = self.mock_connect.call_args[1]
551-
expected_options = "-c search_path=custom_schema,public"
552-
self.assertEqual(call_kwargs["options"], expected_options)
553567

554568
def test_types_casting(self):
555569
"""Test that types are casted correctly"""

0 commit comments

Comments
 (0)