def package_extras_save(extra_dicts, obj, context):
    allow_partial_update = context.get('allow_partial_update', False)
    if ((extra_dicts is None) and allow_partial_update):
        return
    model = context['model']
    session = context['session']
    extras_list = obj.extras_list
    old_extras = dict(((extra.key, extra) for extra in extras_list))
    new_extras = {}
    for extra_dict in (extra_dicts or []):
        if extra_dict.get('deleted'):
            continue
        if (extra_dict['value'] is None):
            pass
        else:
            new_extras[extra_dict['key']] = extra_dict['value']
    for key in (set(new_extras.keys()) - set(old_extras.keys())):
        state = 'active'
        extra = model.PackageExtra(state=state, key=key, value=new_extras[key])
        session.add(extra)
        extras_list.append(extra)
    for key in (set(new_extras.keys()) & set(old_extras.keys())):
        extra = old_extras[key]
        if ((new_extras[key] == extra.value) and (extra.state != 'deleted')):
            continue
        state = 'active'
        extra.value = new_extras[key]
        extra.state = state
        session.add(extra)
    for key in (set(old_extras.keys()) - set(new_extras.keys())):
        extra = old_extras[key]
        if (extra.state == 'deleted'):
            continue
        state = 'deleted'
        extra.state = state
def package_extras_save(extra_dicts, obj, context):
    allow_partial_update = context.get('allow_partial_update', False)
    if ((extra_dicts is None) and allow_partial_update):
        return
    model = context['model']
    session = context['session']
    extras_list = obj.extras_list
    old_extras = dict(((extra.key, extra) for extra in extras_list))
    new_extras = {}
    for extra_dict in (extra_dicts or []):
        if extra_dict.get('deleted'):
            continue
        if (extra_dict['value'] is None):
            pass
        else:
            new_extras[extra_dict['key']] = extra_dict['value']
    for key in (set(new_extras.keys()) - set(old_extras.keys())):
        state = 'active'
        extra = model.PackageExtra(state=state, key=key, value=new_extras[key])
        session.add(extra)
        extras_list.append(extra)
    for key in (set(new_extras.keys()) & set(old_extras.keys())):
        extra = old_extras[key]
        if ((new_extras[key] == extra.value) and (extra.state != 'deleted')):
            continue
        state = 'active'
        extra.value = new_extras[key]
        extra.state = state
        session.add(extra)
    for key in (set(old_extras.keys()) - set(new_extras.keys())):
        extra = old_extras[key]
        if (extra.state == 'deleted'):
            continue
        state = 'deleted'
        extra.state = state