55 Dict ,
66 List ,
77 Optional ,
8- Tuple ,
98 Union ,
109)
1110
@@ -46,37 +45,14 @@ async def add_repos_to_product(
4645 product : models .Product ,
4746 owner : models .User ,
4847 platforms : List [models .Platform ],
49- ignore_errors : bool = False ,
5048):
5149 repos_to_insert = []
5250 repo_tasks = []
5351
54- async def _create_repo (
55- pulp_client : PulpClient ,
56- product_name : str ,
57- owner_name : str ,
58- platform_name : str ,
59- arch : str ,
60- is_debug : bool ,
61- ) -> Tuple [str , str , str , str , str , bool ]:
62- try :
63- return await create_product_repo (
64- pulp_client = pulp_client ,
65- product_name = product_name ,
66- ownername = owner_name ,
67- platform_name = platform_name ,
68- arch = arch ,
69- is_debug = is_debug ,
70- )
71- except Exception :
72- if ignore_errors :
73- return '' , '' , '' , '' , '' , False
74- raise
75-
7652 for platform in platforms :
7753 platform_name = platform .name .lower ()
7854 repo_tasks .extend ((
79- _create_repo (
55+ create_product_repo (
8056 pulp_client ,
8157 product .name ,
8258 owner .username ,
@@ -88,7 +64,7 @@ async def _create_repo(
8864 for is_debug in (True , False )
8965 ))
9066 repo_tasks .append (
91- _create_repo (
67+ create_product_repo (
9268 pulp_client ,
9369 product .name ,
9470 owner .username ,
@@ -107,8 +83,6 @@ async def _create_repo(
10783 export_path ,
10884 is_debug ,
10985 ) in task_results :
110- if not any ((repo_name , repo_url , pulp_href )):
111- continue
11286 repo = models .Repository (
11387 name = repo_name ,
11488 url = repo_url ,
@@ -424,7 +398,6 @@ async def add_platform_to_product(
424398 product_id : int ,
425399 platforms : List [Platform ],
426400 user_id : int ,
427- ignore_errors : bool = False ,
428401):
429402 pulp_client = PulpClient (
430403 settings .pulp_host ,
@@ -435,6 +408,8 @@ async def add_platform_to_product(
435408 db_user = await get_user (session , user_id = user_id )
436409 if not db_user :
437410 raise DataNotFoundError (f"User={ user_id } doesn't exist" )
411+ if not db_product :
412+ raise DataNotFoundError (f"Product={ product_id } doesn't exist" )
438413 if not can_perform (db_product , db_user , actions .UpdateProduct .name ):
439414 raise PermissionDenied (
440415 f'User has no permissions to modify the product "{ db_product .name } "'
@@ -458,10 +433,17 @@ async def add_platform_to_product(
458433 owner = db_product .owner ,
459434 product = db_product ,
460435 platforms = db_platforms ,
461- ignore_errors = ignore_errors ,
462436 )
463- db_product .repositories .extend (repos )
464- session .add_all (repos )
437+ existing_repo_names = {repo .name for repo in db_product .repositories }
438+ new_repos = [
439+ repo
440+ for repo in repos
441+ if repo .name not in existing_repo_names
442+ ]
443+ if not new_repos :
444+ return
445+ db_product .repositories .extend (new_repos )
446+ session .add_all (new_repos )
465447
466448
467449async def get_repo_product (
0 commit comments