File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -744,6 +744,9 @@ def get_column_from_field(field: Any) -> Column: # type: ignore
744
744
"index" : index ,
745
745
"unique" : unique ,
746
746
}
747
+ description = getattr (field_info , "description" , Undefined )
748
+ if description is not Undefined :
749
+ kwargs ["comment" ] = description
747
750
sa_default = Undefined
748
751
if field_info .default_factory :
749
752
sa_default = field_info .default_factory
Original file line number Diff line number Diff line change
1
+ from pytest import LogCaptureFixture
2
+ from sqlmodel import Field , SQLModel , create_engine
3
+
4
+
5
+ def test_sa_column_description (clear_sqlmodel : None , caplog : LogCaptureFixture ) -> None :
6
+ class Team (SQLModel , table = True ):
7
+ id : int = Field (primary_key = True , description = "an id" )
8
+ name : str = Field (description = "a name" )
9
+ age : int = Field ()
10
+
11
+ assert Team .model_fields ["id" ].description == "an id"
12
+ assert Team .model_fields ["name" ].description == "a name"
13
+ assert Team .model_fields ["age" ].description is None
14
+
15
+ engine = create_engine ("sqlite://" , echo = True ) # TODO: this should go to Postgres
16
+ SQLModel .metadata .create_all (engine )
17
+ msgs = []
18
+ for msg in caplog .messages :
19
+ if "COMMENT ON COLUMN" in msg :
20
+ msgs .append (msg )
21
+ assert len (msgs ) == 2
22
+ assert "COMMENT ON COLUMN team.id IS 'an id'" in msgs [0 ]
23
+ assert "COMMENT ON COLUMN team.name IS 'a name'" in msgs [1 ]
You can’t perform that action at this time.
0 commit comments