Skip to content

Commit 8868d09

Browse files
committed
chore: add deprecation warnings for Column helpers
1 parent 1c42c9e commit 8868d09

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

diracx-db/src/diracx/db/sql/utils/types.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import warnings
34
from datetime import datetime
45
from functools import partial
56
from zoneinfo import ZoneInfo
@@ -12,9 +13,39 @@
1213

1314
from .functions import utcnow
1415

15-
Column: partial[RawColumn] = partial(RawColumn, nullable=False)
16-
NullColumn: partial[RawColumn] = partial(RawColumn, nullable=True)
17-
DateNowColumn = partial(Column, type_=DateTime(timezone=True), server_default=utcnow())
16+
17+
def _deprecated(name: str, replacement: str):
18+
warnings.warn(
19+
f"{name} is deprecated and will be removed in a future major release. "
20+
f"Use {replacement} instead.",
21+
DeprecationWarning,
22+
stacklevel=3,
23+
)
24+
25+
26+
_Column: partial[RawColumn] = partial(RawColumn, nullable=False)
27+
28+
29+
def Column(*args, **kwargs): # noqa: N802
30+
_deprecated("Column", "Mapped[...] + mapped_column(...)")
31+
return _Column(*args, **kwargs)
32+
33+
34+
_NullColumn: partial[RawColumn] = partial(RawColumn, nullable=True)
35+
36+
37+
def NullColumn(*args, **kwargs): # noqa: N802
38+
_deprecated("NullColumn", "Mapped[Optional[...]] + mapped_column(...)")
39+
return _NullColumn(*args, **kwargs)
40+
41+
42+
_DateNowColumn = partial(Column, type_=DateTime(timezone=True), server_default=utcnow())
43+
44+
45+
def DateNowColumn(*args, **kwargs): # noqa: N802
46+
_deprecated("DateNowColumn", "Mapped[datetime_now] + mapped_column(...)")
47+
return _DateNowColumn(*args, **kwargs)
48+
1849

1950
# Module-level constants for default timezone values
2051
_DEFAULT_UTC = ZoneInfo("UTC")
@@ -32,6 +63,7 @@
3263

3364

3465
def EnumColumn(name, enum_type, **kwargs): # noqa: N802
66+
_deprecated("EnumColumn", "Mapped[...] + enum_column(...)")
3567
return Column(name, Enum(enum_type, native_enum=False, length=16), **kwargs)
3668

3769

diracx-testing/src/diracx/testing/mock_osdb.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class JobParametersDB(MockOSDBMixin, JobParametersDB):
3737
"""
3838

3939
def __init__(self, connection_kwargs: dict[str, Any]) -> None:
40-
from sqlalchemy import JSON, Column, Integer, MetaData, String, Table
41-
42-
from diracx.db.sql.utils import DateNowColumn
40+
from sqlalchemy import JSON, Column, DateTime, Integer, MetaData, String, Table
4341

4442
# Dynamically create a subclass of BaseSQLDB so we get clearer errors
4543
mocked_db = type(f"Mocked{self.__class__.__name__}", (sql_utils.BaseSQLDB,), {})
@@ -53,7 +51,11 @@ def __init__(self, connection_kwargs: dict[str, Any]) -> None:
5351
for field, field_type in self.fields.items():
5452
match field_type["type"]:
5553
case "date":
56-
column_type = DateNowColumn
54+
column_type = partial(
55+
Column,
56+
type_=DateTime(timezone=True),
57+
server_default=sql_utils.utcnow(),
58+
)
5759
case "long":
5860
column_type = partial(Column, type_=Integer)
5961
case "keyword":

0 commit comments

Comments
 (0)