File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from typing import Annotated
2+
3+ from sqlmodel import Field
4+ from sqlmodel .main import FieldInfoMetadata
5+
6+
7+ def test_field_info_metadata_is_hashable ():
8+ """FieldInfoMetadata must be hashable so that Annotated types containing it
9+ can be used in sets (e.g. FastAPI's OpenAPI schema generation)."""
10+ meta = FieldInfoMetadata (primary_key = True )
11+ hash (meta )
12+
13+
14+ def test_annotated_with_field_info_metadata_in_set ():
15+ """Annotated types carrying FieldInfoMetadata must work inside a set,
16+ which is required by FastAPI's get_definitions()."""
17+ t = Annotated [int , FieldInfoMetadata (unique = True )]
18+ s = {t }
19+ assert t in s
20+
21+
22+ def test_annotated_field_type_in_set ():
23+ """Realistic scenario: custom Annotated field aliases used in a set."""
24+ PositiveInt = Annotated [int , Field (ge = 0 )]
25+ ShortStr = Annotated [str , Field (max_length = 32 )]
26+
27+ s = {PositiveInt , ShortStr }
28+ assert PositiveInt in s
29+ assert ShortStr in s
You can’t perform that action at this time.
0 commit comments