'All subnet update operations safe to enclose in a transaction.
:param context: neutron api request context
:param id: subnet id
:param subnet: API request dictionary'

def _update_subnet_precommit(self, context, id, subnet):

    s = subnet['subnet']
    new_cidr = s.get('cidr')
    db_subnet = self._get_subnet(context, id)
    orig = self._make_subnet_dict(db_subnet, fields=None, context=context)
    s['ip_version'] = db_subnet.ip_version
    s['cidr'] = db_subnet.cidr
    s['id'] = db_subnet.id
    s['tenant_id'] = db_subnet.tenant_id
    s['subnetpool_id'] = db_subnet.subnetpool_id
    self._validate_subnet(context, s, cur_subnet=db_subnet)
    db_pools = [netaddr.IPRange(p['first_ip'], p['last_ip']) for p in db_subnet.allocation_pools]
    if (new_cidr and ipv6_utils.is_ipv6_pd_enabled(s)):
        s['cidr'] = new_cidr
        net = netaddr.IPNetwork(s['cidr'], s['ip_version'])
        s['gateway_ip'] = utils.get_first_host_ip(net, s['ip_version'])
        s['allocation_pools'] = self._update_allocation_pools(s)
    range_pools = None
    if (s.get('allocation_pools') is not None):
        range_pools = self.ipam.pools_to_ip_range(s['allocation_pools'])
        self.ipam.validate_allocation_pools(range_pools, s['cidr'])
        s['allocation_pools'] = range_pools
    gateway_ip = s.get('gateway_ip', db_subnet.gateway_ip)
    gateway_ip_changed = (gateway_ip != db_subnet.gateway_ip)
    if (gateway_ip_changed or (s.get('allocation_pools') is not None)):
        pools = (range_pools if (range_pools is not None) else db_pools)
        if gateway_ip:
            self.ipam.validate_gw_out_of_pools(gateway_ip, pools)
    kwargs = {'context': context, 'original_subnet': orig, 'request': s}
    registry.notify(resources.SUBNET, events.BEFORE_UPDATE, self, **kwargs)
    with db_api.context_manager.writer.using(context):
        (subnet, changes) = self.ipam.update_db_subnet(context, id, s, db_pools)
    if (subnet in context.session):
        context.session.expire(subnet)
    return (self._make_subnet_dict(subnet, context=context), orig)
