3131from  app .schemas .activity  import  ActivityCreate , ActivityUpdate 
3232from  app .schemas .auth  import  UserContext , UserContextWithProjectId , UserProfile 
3333from  app .schemas .types  import  ListResponse , PaginationResponse 
34+ from  app .schemas .utils  import  NOT_SET 
3435from  app .utils .uuid  import  create_uuid 
3536
3637
@@ -354,15 +355,17 @@ def router_update_one[T: BaseModel, I: Identifiable](
354355    id_ : uuid .UUID ,
355356    db : Session ,
356357    db_model_class : type [I ],
357-     user_context : UserContext ,
358+     user_context : UserContext   |   None ,
358359    json_model : BaseModel ,
359360    response_schema_class : type [T ],
360361    apply_operations : ApplyOperations  |  None  =  None ,
361362):
362363    query  =  (
363364        sa .select (db_model_class ).where (db_model_class .id  ==  id_ ).with_for_update (of = db_model_class )
364365    )
365-     if  id_model_class  :=  get_declaring_class (db_model_class , "authorized_project_id" ):
366+     if  user_context  and  (
367+         id_model_class  :=  get_declaring_class (db_model_class , "authorized_project_id" )
368+     ):
366369        query  =  constrain_to_private_entities (query , user_context , db_model_class = id_model_class )
367370    if  apply_operations :
368371        query  =  apply_operations (query )
@@ -427,13 +430,15 @@ def router_update_activity_one[T: BaseModel, I: Activity](
427430    id_ : uuid .UUID ,
428431    db : Session ,
429432    db_model_class : type [I ],
430-     user_context : UserContext  |  UserContextWithProjectId ,
433+     user_context : UserContext  |  UserContextWithProjectId   |   None ,
431434    json_model : ActivityUpdate ,
432435    response_schema_class : type [T ],
433436    apply_operations : ApplyOperations  |  None  =  None ,
434437) ->  T :
435438    query  =  sa .select (db_model_class ).where (db_model_class .id  ==  id_ )
436-     if  id_model_class  :=  get_declaring_class (db_model_class , "authorized_project_id" ):
439+     if  user_context  and  (
440+         id_model_class  :=  get_declaring_class (db_model_class , "authorized_project_id" )
441+     ):
437442        query  =  constrain_to_accessible_entities (
438443            query , user_context .project_id , db_model_class = id_model_class 
439444        )
@@ -446,21 +451,24 @@ def router_update_activity_one[T: BaseModel, I: Activity](
446451    update_data  =  json_model .model_dump (
447452        exclude_unset = True ,
448453        exclude_none = True ,
449-         exclude_defaults = True ,
450454        exclude = {"used_ids" , "generated_ids" },
455+         exclude_defaults = True ,  # ignore NOT_SET default values 
451456    )
452457
453458    for  key , value  in  update_data .items ():
454459        setattr (obj , key , value )
455460
456-     if  generated_ids  :=  json_model .generated_ids :
461+     # ignore NOT_SET values 
462+     generated_ids  =  json_model .generated_ids  if  json_model .generated_ids  !=  NOT_SET  else  []
463+ 
464+     if  generated_ids :
457465        if  obj .generated :
458466            raise  HTTPException (
459467                status_code = 404 ,
460468                detail = "It is forbidden to update generated_ids if they exist." ,
461469            )
462470
463-         if  (
471+         if  user_context   and   (
464472            unaccessible_entities  :=  db .execute (
465473                select_unauthorized_entities (generated_ids , user_context .project_id )
466474            )
0 commit comments