3737
3838
3939class PydanticModel (BaseModel ):
40-
4140 @classmethod
4241 def _get_all_keys_to_check_in_db (cls ):
42+ """Class that returns request specific keys to check."""
4343 raise NotImplementedError ("Not implemented" )
4444
4545 def get_keys_to_check_in_db (self ):
4646 """Filter keys, which need to be checked in db. Return only a keys that are set to values."""
47- return [
48- k for k in self ._get_all_keys_to_check_in_db () if getattr (self , k , None )
49- ]
47+ return [k for k in self ._get_all_keys_to_check_in_db () if getattr (self , k , None )]
5048
5149
5250class AddPydanticModel (PydanticModel ):
@@ -66,14 +64,16 @@ class AddPydanticModel(PydanticModel):
6664 AfterValidator (images_format_check ),
6765 ]
6866 cnr_token : Optional [SecretStr ] = None # deprecated
69- check_related_images : Optional [bool ] = None # old request without this parameter will not have False but None
67+ # TODO remove this comment -> old request without this parameter will not have False but None
68+ check_related_images : Optional [bool ] = None
7069 deprecation_list : Annotated [
7170 Optional [List [str ]],
7271 AfterValidator (get_unique_deprecation_list_items ),
7372 AfterValidator (images_format_check ),
7473 ] = [] # deprecated
7574 distribution_scope : Annotated [
76- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
75+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
76+ BeforeValidator (distribution_scope_lower ),
7777 ] = None
7878 force_backport : Optional [bool ] = False # deprecated
7979 from_index : Annotated [str , AfterValidator (image_format_check )]
@@ -102,7 +102,7 @@ def verify_graph_update_mode_with_index_image(self) -> 'AddPydanticModel':
102102 @model_validator (mode = 'after' )
103103 def from_index_needed_if_no_bundles (self ) -> 'AddPydanticModel' :
104104 """
105- Check if no bundles and `from_index is specified
105+ Check if no bundles and `from_index is specified.
106106
107107 if no bundles and no from index then an empty index will be created which is a no-op
108108 """
@@ -113,7 +113,7 @@ def from_index_needed_if_no_bundles(self) -> 'AddPydanticModel':
113113 # TODO remove this comment -> Validator from RequestADD class
114114 @model_validator (mode = 'after' )
115115 def bundles_needed_with_check_related_images (self ) -> 'AddPydanticModel' :
116- """Verify that `check_related_images` is specified when bundles are specified"""
116+ """Verify that `check_related_images` is specified when bundles are specified. """
117117 if self .check_related_images and not self .bundles :
118118 raise ValidationError (
119119 '"check_related_images" must be specified only when bundles are specified'
@@ -123,7 +123,6 @@ def bundles_needed_with_check_related_images(self) -> 'AddPydanticModel':
123123 def get_json_for_request (self ):
124124 """Return json with the parameters we store in the db."""
125125 return self .model_dump (
126- # include=["deprecation_list"],
127126 exclude = [
128127 "add_arches" ,
129128 "build_tags" ,
@@ -135,7 +134,6 @@ def get_json_for_request(self):
135134 exclude_none = True ,
136135 )
137136
138-
139137 def _get_all_keys_to_check_in_db (self ):
140138 return ["binary_image" , "bundles" , "deprecation_list" , "from_index" ]
141139
@@ -150,7 +148,8 @@ class RmPydanticModel(PydanticModel):
150148 ] = None
151149 build_tags : Optional [List [str ]] = []
152150 distribution_scope : Annotated [
153- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
151+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
152+ BeforeValidator (distribution_scope_lower ),
154153 ] = None
155154 from_index : Annotated [str , AfterValidator (image_format_check )]
156155 operators : Annotated [List [str ], AfterValidator (length_validator )]
@@ -167,7 +166,12 @@ def verify_overwrite_from_index_token(self) -> 'RmPydanticModel':
167166 def get_json_for_request (self ):
168167 """Return json with the parameters we store in the db."""
169168 return self .model_dump (
170- exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
169+ exclude = [
170+ "add_arches" ,
171+ "build_tags" ,
172+ "overwrite_from_index" ,
173+ "overwrite_from_index_token" ,
174+ ],
171175 exclude_none = True ,
172176 )
173177
@@ -228,10 +232,11 @@ class MergeIndexImagePydanticModel(PydanticModel):
228232 AfterValidator (images_format_check ),
229233 ] = []
230234 distribution_scope : Annotated [
231- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
235+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
236+ BeforeValidator (distribution_scope_lower ),
232237 ] = None
233238 graph_update_mode : Optional [GRAPH_MODE_LITERAL ] = None
234- overwrite_target_index : Optional [bool ] = False # Why do we need this bool? Isn't the token enough?
239+ overwrite_target_index : Optional [bool ] = False
235240 overwrite_target_index_token : Optional [SecretStr ] = None
236241 source_from_index : Annotated [str , AfterValidator (image_format_check )]
237242 target_index : Annotated [Optional [str ], AfterValidator (image_format_check )] = None
@@ -260,7 +265,13 @@ def get_json_for_request(self):
260265 )
261266
262267 def _get_all_keys_to_check_in_db (self ):
263- return ["binary_image" , "deprecation_list" , "source_from_index" , "target_index" , "target_index" ]
268+ return [
269+ "binary_image" ,
270+ "deprecation_list" ,
271+ "source_from_index" ,
272+ "target_index" ,
273+ "target_index" ,
274+ ]
264275
265276
266277class CreateEmptyIndexPydanticModel (PydanticModel ):
@@ -276,8 +287,10 @@ class CreateEmptyIndexPydanticModel(PydanticModel):
276287 AfterValidator (image_format_check ),
277288 AfterValidator (length_validator ),
278289 ]
279- labels : Optional [Dict [str , str ]] = None # old request without this parameter will not have empty labels
280- output_fbc : Optional [bool ] = None # old request without this parameter will not have empty output_fbc
290+ # TODO (remove comment) old request without this parameter will not have empty labels
291+ labels : Optional [Dict [str , str ]] = None
292+ # TODO (remove comment) old request without this parameter will not have empty output_fbc
293+ output_fbc : Optional [bool ] = None
281294
282295 def get_json_for_request (self ):
283296 """Return json with the parameters we store in the db."""
@@ -305,7 +318,6 @@ def get_json_for_request(self):
305318 exclude_none = True ,
306319 )
307320
308-
309321 def _get_all_keys_to_check_in_db (self ):
310322 return ["parent_bundle_image" ]
311323
@@ -317,15 +329,17 @@ class FbcOperationsPydanticModel(PydanticModel):
317329 AfterValidator (image_format_check ),
318330 AfterValidator (binary_image_check ),
319331 ] = None
332+ # TODO (remove comment) old request without this parameter will not have empty list but None
320333 bundles : Annotated [
321334 Optional [List [str ]],
322335 AfterValidator (length_validator ),
323336 AfterValidator (get_unique_bundles ),
324337 AfterValidator (images_format_check ),
325- ] = None # old request without this parameter will not have empty list but None
338+ ] = None
326339 build_tags : Optional [List [str ]] = []
327340 distribution_scope : Annotated [
328- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
341+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
342+ BeforeValidator (distribution_scope_lower ),
329343 ] = None
330344 fbc_fragment : Annotated [
331345 str ,
@@ -349,7 +363,12 @@ def verify_overwrite_from_index_token(self) -> 'FbcOperationsPydanticModel':
349363 def get_json_for_request (self ):
350364 """Return json with the parameters we store in the db."""
351365 return self .model_dump (
352- exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
366+ exclude = [
367+ "add_arches" ,
368+ "build_tags" ,
369+ "overwrite_from_index" ,
370+ "overwrite_from_index_token" ,
371+ ],
353372 exclude_none = True ,
354373 )
355374
0 commit comments