@@ -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