@@ -646,7 +646,9 @@ async def upload_score_set_variant_data(
646646 return item
647647
648648
649- @router .put ("/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}})
649+ @router .put (
650+ "/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}}, response_model_exclude_none = True
651+ )
650652async def update_score_set (
651653 * ,
652654 urn : str ,
@@ -668,68 +670,65 @@ async def update_score_set(
668670
669671 assert_permission (user_data , item , Action .UPDATE )
670672
671- # Editing unpublished score set
672- if item .private is True :
673- license_ = None
673+ for var , value in vars (item_update ).items ():
674+ if var not in [
675+ "contributors" ,
676+ "score_ranges" ,
677+ "doi_identifiers" ,
678+ "experiment_urn" ,
679+ "license_id" ,
680+ "secondary_publication_identifiers" ,
681+ "primary_publication_identifiers" ,
682+ "target_genes" ,
683+ ]:
684+ setattr (item , var , value ) if value else None
685+
686+ if item_update .license_id is not None :
687+ save_to_logging_context ({"license" : item_update .license_id })
688+ license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
689+
690+ if not license_ :
691+ logger .info (
692+ msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
693+ )
694+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
674695
675- if item_update .license_id is not None :
676- save_to_logging_context ({"license" : item_update .license_id })
677- license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
696+ item .license = license_
678697
679- if not license_ :
680- logger .info (
681- msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
682- )
683- raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
698+ item .doi_identifiers = [
699+ await find_or_create_doi_identifier (db , identifier .identifier )
700+ for identifier in item_update .doi_identifiers or []
701+ ]
702+ primary_publication_identifiers = [
703+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
704+ for identifier in item_update .primary_publication_identifiers or []
705+ ]
706+ publication_identifiers = [
707+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
708+ for identifier in item_update .secondary_publication_identifiers or []
709+ ] + primary_publication_identifiers
684710
685- item .license = license_
711+ # create a temporary `primary` attribute on each of our publications that indicates
712+ # to our association proxy whether it is a primary publication or not
713+ primary_identifiers = [p .identifier for p in primary_publication_identifiers ]
714+ for publication in publication_identifiers :
715+ setattr (publication , "primary" , publication .identifier in primary_identifiers )
686716
687- for var , value in vars (item_update ).items ():
688- if var not in [
689- "contributors" ,
690- "score_ranges" ,
691- "doi_identifiers" ,
692- "experiment_urn" ,
693- "license_id" ,
694- "secondary_publication_identifiers" ,
695- "primary_publication_identifiers" ,
696- "target_genes" ,
697- ]:
698- setattr (item , var , value ) if value else None
699-
700- try :
701- item .contributors = [
702- await find_or_create_contributor (db , contributor .orcid_id )
703- for contributor in item_update .contributors or []
704- ]
705- except NonexistentOrcidUserError as e :
706- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
707- raise pydantic .ValidationError (
708- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
709- model = score_set .ScoreSetUpdate ,
710- )
717+ item .publication_identifiers = publication_identifiers
711718
712- item .doi_identifiers = [
713- await find_or_create_doi_identifier (db , identifier .identifier )
714- for identifier in item_update .doi_identifiers or []
715- ]
716- primary_publication_identifiers = [
717- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
718- for identifier in item_update .primary_publication_identifiers or []
719+ try :
720+ item .contributors = [
721+ await find_or_create_contributor (db , contributor .orcid_id ) for contributor in item_update .contributors or []
719722 ]
720- publication_identifiers = [
721- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
722- for identifier in item_update .secondary_publication_identifiers or []
723- ] + primary_publication_identifiers
724-
725- # create a temporary `primary` attribute on each of our publications that indicates
726- # to our association proxy whether it is a primary publication or not
727- primary_identifiers = [pub .identifier for pub in primary_publication_identifiers ]
728- for publication in publication_identifiers :
729- setattr (publication , "primary" , publication .identifier in primary_identifiers )
730-
731- item .publication_identifiers = publication_identifiers
723+ except NonexistentOrcidUserError as e :
724+ logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
725+ raise pydantic .ValidationError (
726+ [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
727+ model = score_set .ScoreSetUpdate ,
728+ )
732729
730+ # Score set has not been published and attributes affecting scores may still be edited.
731+ if item .private :
733732 if item_update .score_ranges :
734733 item .score_ranges = item_update .score_ranges .dict ()
735734 else :
@@ -884,35 +883,8 @@ async def update_score_set(
884883 if job is not None :
885884 save_to_logging_context ({"worker_job_id" : job .job_id })
886885 logger .info (msg = "Enqueud variant creation job." , extra = logging_context ())
887-
888- for var , value in vars (item_update ).items ():
889- if var not in [
890- "score_ranges" ,
891- "contributors" ,
892- "doi_identifiers" ,
893- "experiment_urn" ,
894- "primary_publication_identifiers" ,
895- "secondary_publication_identifiers" ,
896- "target_genes" ,
897- ]:
898- setattr (item , var , value ) if value else None
899-
900- # Editing published score set
901886 else :
902- for var , value in vars (item_update ).items ():
903- if var in ["title" , "method_text" , "abstract_text" , "short_description" ]:
904- setattr (item , var , value ) if value else None
905- try :
906- item .contributors = [
907- await find_or_create_contributor (db , contributor .orcid_id )
908- for contributor in item_update .contributors or []
909- ]
910- except NonexistentOrcidUserError as e :
911- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
912- raise pydantic .ValidationError (
913- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
914- model = score_set .ScoreSetUpdate ,
915- )
887+ logger .debug (msg = "Skipped score range and target gene update. Score set is published." , extra = logging_context ())
916888
917889 db .add (item )
918890 db .commit ()
0 commit comments