def get_security_group(self, context, id, fields=None, tenant_id=None):

        if tenant_id:
            tmp_context_tenant_id = context.tenant_id
            context.tenant_id = tenant_id

        try:
            with context.session.begin(subtransactions=True):
                ret = self._make_security_group_dict(self._get_security_group(
                                                     context, id), fields)
                ret['security_group_rules'] = self.get_security_group_rules(
                    context, {'security_group_id': [id]})
        finally:
            if tenant_id:
                context.tenant_id = tmp_context_tenant_id
        return ret
Tenant id is given to handle the case when creating a security
dataset/ETHPy150Open openstack/neutron/neutron/db/securitygroups_db.py/SecurityGroupDbMixin.get_security_group