Skip to content

Commit 0c0c3aa

Browse files
committed
🔧 Add unit tests to cover handling of obsolete sa_column-parameters
1 parent 19171db commit 0c0c3aa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_sa_column.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""These test cases should become obsolete once `sa_column`-parameters are dropped from `Field`."""
2+
3+
import pytest
4+
from pydantic.config import BaseConfig
5+
from pydantic.fields import ModelField
6+
from sqlalchemy.sql.schema import CheckConstraint, Column, ForeignKey
7+
from sqlmodel.main import Field, FieldInfo, get_column_from_field
8+
9+
10+
def test_sa_column_params_raise_warnings():
11+
with pytest.warns(DeprecationWarning):
12+
Field(sa_column=Column())
13+
with pytest.warns(DeprecationWarning):
14+
Field(sa_column_args=[ForeignKey("foo.id"), CheckConstraint(">1")])
15+
with pytest.warns(DeprecationWarning):
16+
Field(sa_column_kwargs={"name": "foo"})
17+
18+
19+
def test_sa_column_overrides_other_params():
20+
col = Column()
21+
field = ModelField(
22+
name="foo",
23+
type_=str,
24+
class_validators=None,
25+
model_config=BaseConfig,
26+
field_info=FieldInfo(
27+
index=True, # should be ignored
28+
sa_column=col,
29+
),
30+
)
31+
output = get_column_from_field(field)
32+
assert output is col
33+
assert output.index is None

0 commit comments

Comments
 (0)