File tree Expand file tree Collapse file tree 3 files changed +8
-29
lines changed
Expand file tree Collapse file tree 3 files changed +8
-29
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,13 @@ def activate(
172172 self .connection = connection
173173 if self .connection is None :
174174 self .connection = _get_singleton_connection ()
175+ if self .connection ._config .get ("database.database_prefix" ):
176+ warnings .warn (
177+ "database_prefix is deprecated and will be removed in DataJoint 2.3. "
178+ "Use database.name to select a PostgreSQL database instead." ,
179+ DeprecationWarning ,
180+ stacklevel = 2 ,
181+ )
175182 self .database = schema_name
176183 if create_schema is not None :
177184 self .create_schema = create_schema
Original file line number Diff line number Diff line change @@ -223,19 +223,6 @@ def set_default_port_from_backend(self) -> "DatabaseSettings":
223223 self .port = 5432 if self .backend == "postgresql" else 3306
224224 return self
225225
226- @model_validator (mode = "after" )
227- def warn_database_prefix_deprecated (self ) -> "DatabaseSettings" :
228- """Emit deprecation warning when database_prefix is set."""
229- if self .database_prefix :
230- import warnings
231-
232- warnings .warn (
233- "database_prefix is deprecated and will be removed in DataJoint 2.3. "
234- "Use database.name to select a PostgreSQL database instead." ,
235- DeprecationWarning ,
236- stacklevel = 2 ,
237- )
238- return self
239226
240227
241228class ConnectionSettings (BaseSettings ):
Original file line number Diff line number Diff line change @@ -800,23 +800,8 @@ def test_database_name_override_context_manager(self):
800800 assert dj .config .database .name == "override_db"
801801 assert dj .config .database .name == original
802802
803- def test_database_prefix_deprecation_warning (self , monkeypatch ):
804- """Non-empty database_prefix emits DeprecationWarning."""
805- import warnings
806-
807- from datajoint .settings import DatabaseSettings
808-
809- monkeypatch .setenv ("DJ_DATABASE_PREFIX" , "test_" )
810- with warnings .catch_warnings (record = True ) as w :
811- warnings .simplefilter ("always" )
812- DatabaseSettings ()
813- deprecation_warnings = [
814- x for x in w if issubclass (x .category , DeprecationWarning ) and "database_prefix" in str (x .message )
815- ]
816- assert len (deprecation_warnings ) >= 1
817-
818803 def test_database_prefix_empty_no_warning (self ):
819- """Empty database_prefix does not emit DeprecationWarning."""
804+ """Empty database_prefix does not emit DeprecationWarning at config load ."""
820805 import warnings
821806
822807 from datajoint .settings import DatabaseSettings
You can’t perform that action at this time.
0 commit comments