def create(*, db_session, task_in: TaskCreate) -> Task:
    'Create a new task.'
    incident = incident_service.get(db_session=db_session, incident_id=task_in.incident.id)
    tickets = [ticket_service.get_or_create_by_weblink(db_session=db_session, weblink=t.weblink, resource_type='task-ticket') for t in task_in.tickets]
    assignees = []
    for i in task_in.assignees:
        assignee = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=i.individual.email)
        if assignee:
            assignees.append(assignee)
    creator_email = None
    if (not task_in.creator):
        creator_email = task_in.owner.individual.email
    else:
        creator_email = task_in.creator.individual.email
    creator = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=creator_email)
    if (not assignees):
        assignees.append(creator)
    if task_in.owner:
        owner = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=task_in.owner.individual.email)
    else:
        owner = incident.commander
    task = Task(**task_in.dict(exclude={'assignees', 'owner', 'incident', 'creator', 'tickets'}), creator=creator, owner=owner, assignees=assignees, incident=incident, tickets=tickets)
    event_service.log(db_session=db_session, source='Dispatch Core App', description='New incident task created', details={'weblink': task.weblink}, incident_id=incident.id)
    db_session.add(task)
    db_session.commit()
    return task
Create a new task.
def create(*, db_session, task_in: TaskCreate) -> Task:
    
    incident = incident_service.get(db_session=db_session, incident_id=task_in.incident.id)
    tickets = [ticket_service.get_or_create_by_weblink(db_session=db_session, weblink=t.weblink, resource_type='task-ticket') for t in task_in.tickets]
    assignees = []
    for i in task_in.assignees:
        assignee = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=i.individual.email)
        if assignee:
            assignees.append(assignee)
    creator_email = None
    if (not task_in.creator):
        creator_email = task_in.owner.individual.email
    else:
        creator_email = task_in.creator.individual.email
    creator = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=creator_email)
    if (not assignees):
        assignees.append(creator)
    if task_in.owner:
        owner = incident_flows.incident_add_or_reactivate_participant_flow(db_session=db_session, incident_id=incident.id, user_email=task_in.owner.individual.email)
    else:
        owner = incident.commander
    task = Task(**task_in.dict(exclude={'assignees', 'owner', 'incident', 'creator', 'tickets'}), creator=creator, owner=owner, assignees=assignees, incident=incident, tickets=tickets)
    event_service.log(db_session=db_session, source='Dispatch Core App', description='New incident task created', details={'weblink': task.weblink}, incident_id=incident.id)
    db_session.add(task)
    db_session.commit()
    return task