File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments