1
1
# file with pydantic models
2
- import datetime
3
2
from typing import List , Optional , Union
4
-
5
- import peppy
6
- from pydantic import BaseModel , Extra , Field , validator
3
+ from pydantic import BaseModel , Extra , Field , validator , ConfigDict , field_validator
7
4
8
5
9
6
class AnnotationModel (BaseModel ):
@@ -21,12 +18,14 @@ class AnnotationModel(BaseModel):
21
18
submission_date : Optional [str ]
22
19
digest : Optional [str ]
23
20
pep_schema : Optional [str ]
21
+ pop : Optional [bool ] = False
24
22
25
- class Config :
26
- allow_population_by_field_name = True
27
- validate_assignment = True
23
+ model_config = ConfigDict (
24
+ validate_assignment = True ,
25
+ populate_by_name = True ,
26
+ )
28
27
29
- @validator ("is_private" )
28
+ @field_validator ("is_private" )
30
29
def is_private_should_be_bool (cls , v ):
31
30
if not isinstance (v , bool ):
32
31
return False
@@ -71,20 +70,20 @@ class UpdateItems(BaseModel):
71
70
Model used for updating individual items in db
72
71
"""
73
72
74
- name : Optional [str ]
75
- description : Optional [str ]
76
- tag : Optional [str ]
77
- is_private : Optional [bool ]
78
- pep_schema : Optional [str ]
79
- digest : Optional [str ]
80
- config : Optional [dict ]
81
- samples : Optional [List [dict ]]
82
- subsamples : Optional [List [List [dict ]]]
83
- description : Optional [ str ]
84
-
85
- class Config :
86
- arbitrary_types_allowed = True
87
- extra = Extra . forbid
73
+ name : Optional [str ] = None
74
+ description : Optional [str ] = None
75
+ tag : Optional [str ] = None
76
+ is_private : Optional [bool ] = None
77
+ pep_schema : Optional [str ] = None
78
+ digest : Optional [str ] = None
79
+ config : Optional [dict ] = None
80
+ samples : Optional [List [dict ]] = None
81
+ subsamples : Optional [List [List [dict ]]] = None
82
+
83
+ model_config = ConfigDict (
84
+ arbitrary_types_allowed = True ,
85
+ extra = "forbid" ,
86
+ )
88
87
89
88
@property
90
89
def number_of_samples (self ) -> Union [int , None ]:
@@ -99,37 +98,35 @@ class UpdateModel(BaseModel):
99
98
Model used for updating individual items and creating sql string in the code
100
99
"""
101
100
102
- config : Optional [dict ]
101
+ config : Optional [dict ] = None
103
102
name : Optional [str ] = None
104
103
tag : Optional [str ] = None
105
- private : Optional [bool ] = Field (alias = "is_private" )
106
- digest : Optional [str ]
107
- number_of_samples : Optional [int ]
108
- pep_schema : Optional [str ]
104
+ private : Optional [bool ] = Field (alias = "is_private" , default = None )
105
+ digest : Optional [str ] = None
106
+ number_of_samples : Optional [int ] = None
107
+ pep_schema : Optional [str ] = None
109
108
description : Optional [str ] = ""
110
109
# last_update_date: Optional[datetime.datetime] = datetime.datetime.now(datetime.timezone.utc)
111
110
112
- @validator ("tag" , "name" )
111
+ @field_validator ("tag" , "name" )
113
112
def value_must_not_be_empty (cls , v ):
114
113
if "" == v :
115
114
return None
116
115
return v
117
116
118
- @validator ("tag" , "name" )
117
+ @field_validator ("tag" , "name" )
119
118
def value_must_be_lowercase (cls , v ):
120
119
if v :
121
120
return v .lower ()
122
121
return v
123
122
124
- @validator ("tag" , "name" )
123
+ @field_validator ("tag" , "name" )
125
124
def value_should_not_contain_question (cls , v ):
126
125
if "?" in v :
127
126
return ValueError ("Question mark (?) is prohibited in name and tag." )
128
127
return v
129
128
130
- class Config :
131
- extra = Extra .forbid
132
- allow_population_by_field_name = True
129
+ model_config = ConfigDict (populate_by_name = True , extra = "forbid" )
133
130
134
131
135
132
class NamespaceInfo (BaseModel ):
0 commit comments