@@ -651,7 +651,9 @@ async def upload_score_set_variant_data(
651651 return item
652652
653653
654- @router .put ("/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}})
654+ @router .put (
655+ "/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}}, response_model_exclude_none = True
656+ )
655657async def update_score_set (
656658 * ,
657659 urn : str ,
@@ -673,68 +675,65 @@ async def update_score_set(
673675
674676 assert_permission (user_data , item , Action .UPDATE )
675677
676- # Editing unpublished score set
677- if item .private is True :
678- license_ = None
678+ for var , value in vars (item_update ).items ():
679+ if var not in [
680+ "contributors" ,
681+ "score_ranges" ,
682+ "doi_identifiers" ,
683+ "experiment_urn" ,
684+ "license_id" ,
685+ "secondary_publication_identifiers" ,
686+ "primary_publication_identifiers" ,
687+ "target_genes" ,
688+ ]:
689+ setattr (item , var , value ) if value else None
690+
691+ if item_update .license_id is not None :
692+ save_to_logging_context ({"license" : item_update .license_id })
693+ license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
694+
695+ if not license_ :
696+ logger .info (
697+ msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
698+ )
699+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
679700
680- if item_update .license_id is not None :
681- save_to_logging_context ({"license" : item_update .license_id })
682- license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
701+ item .license = license_
683702
684- if not license_ :
685- logger .info (
686- msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
687- )
688- raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
703+ item .doi_identifiers = [
704+ await find_or_create_doi_identifier (db , identifier .identifier )
705+ for identifier in item_update .doi_identifiers or []
706+ ]
707+ primary_publication_identifiers = [
708+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
709+ for identifier in item_update .primary_publication_identifiers or []
710+ ]
711+ publication_identifiers = [
712+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
713+ for identifier in item_update .secondary_publication_identifiers or []
714+ ] + primary_publication_identifiers
689715
690- item .license = license_
716+ # create a temporary `primary` attribute on each of our publications that indicates
717+ # to our association proxy whether it is a primary publication or not
718+ primary_identifiers = [p .identifier for p in primary_publication_identifiers ]
719+ for publication in publication_identifiers :
720+ setattr (publication , "primary" , publication .identifier in primary_identifiers )
691721
692- for var , value in vars (item_update ).items ():
693- if var not in [
694- "contributors" ,
695- "score_ranges" ,
696- "doi_identifiers" ,
697- "experiment_urn" ,
698- "license_id" ,
699- "secondary_publication_identifiers" ,
700- "primary_publication_identifiers" ,
701- "target_genes" ,
702- ]:
703- setattr (item , var , value ) if value else None
704-
705- try :
706- item .contributors = [
707- await find_or_create_contributor (db , contributor .orcid_id )
708- for contributor in item_update .contributors or []
709- ]
710- except NonexistentOrcidUserError as e :
711- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
712- raise pydantic .ValidationError (
713- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
714- model = score_set .ScoreSetUpdate ,
715- )
722+ item .publication_identifiers = publication_identifiers
716723
717- item .doi_identifiers = [
718- await find_or_create_doi_identifier (db , identifier .identifier )
719- for identifier in item_update .doi_identifiers or []
720- ]
721- primary_publication_identifiers = [
722- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
723- for identifier in item_update .primary_publication_identifiers or []
724+ try :
725+ item .contributors = [
726+ await find_or_create_contributor (db , contributor .orcid_id ) for contributor in item_update .contributors or []
724727 ]
725- publication_identifiers = [
726- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
727- for identifier in item_update .secondary_publication_identifiers or []
728- ] + primary_publication_identifiers
729-
730- # create a temporary `primary` attribute on each of our publications that indicates
731- # to our association proxy whether it is a primary publication or not
732- primary_identifiers = [pub .identifier for pub in primary_publication_identifiers ]
733- for publication in publication_identifiers :
734- setattr (publication , "primary" , publication .identifier in primary_identifiers )
735-
736- item .publication_identifiers = publication_identifiers
728+ except NonexistentOrcidUserError as e :
729+ logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
730+ raise pydantic .ValidationError (
731+ [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
732+ model = score_set .ScoreSetUpdate ,
733+ )
737734
735+ # Score set has not been published and attributes affecting scores may still be edited.
736+ if item .private :
738737 if item_update .score_ranges :
739738 item .score_ranges = item_update .score_ranges .dict ()
740739 else :
@@ -889,35 +888,8 @@ async def update_score_set(
889888 if job is not None :
890889 save_to_logging_context ({"worker_job_id" : job .job_id })
891890 logger .info (msg = "Enqueud variant creation job." , extra = logging_context ())
892-
893- for var , value in vars (item_update ).items ():
894- if var not in [
895- "score_ranges" ,
896- "contributors" ,
897- "doi_identifiers" ,
898- "experiment_urn" ,
899- "primary_publication_identifiers" ,
900- "secondary_publication_identifiers" ,
901- "target_genes" ,
902- ]:
903- setattr (item , var , value ) if value else None
904-
905- # Editing published score set
906891 else :
907- for var , value in vars (item_update ).items ():
908- if var in ["title" , "method_text" , "abstract_text" , "short_description" ]:
909- setattr (item , var , value ) if value else None
910- try :
911- item .contributors = [
912- await find_or_create_contributor (db , contributor .orcid_id )
913- for contributor in item_update .contributors or []
914- ]
915- except NonexistentOrcidUserError as e :
916- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
917- raise pydantic .ValidationError (
918- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
919- model = score_set .ScoreSetUpdate ,
920- )
892+ logger .debug (msg = "Skipped score range and target gene update. Score set is published." , extra = logging_context ())
921893
922894 db .add (item )
923895 db .commit ()
0 commit comments