Exemplo n.º 1
0
    def _get_constrained_instance_match(self, session):
        """Returns instance and constraint of if-match criterion if present.

        Checks the context associated with the session for compare-and-swap
        update revision number constraints. If one is found, this returns the
        instance that is constrained as well as the requested revision number
        to match.
        """
        context = session.info.get('using_context')
        if context:
            # NOTE(ralonsoh): use "pop_transaction_constraint" once implemented
            criteria = context.get_transaction_constraint()
            context.clear_transaction_constraint()
        else:
            criteria = None
        if not criteria:
            return None, None
        match = criteria.if_revision_match
        mmap = standard_attr.get_standard_attr_resource_model_map()
        model = mmap.get(criteria.resource)
        if not model:
            msg = _("Revision matching not supported for this resource")
            raise exc.BadRequest(resource=criteria.resource, msg=msg)
        instance = self._find_instance_by_column_value(
            session, model, 'id', criteria.resource_id)
        return instance, match
Exemplo n.º 2
0
    def _get_constrained_instance_match(self, session):
        """Returns instance and constraint of if-match criterion if present.

        Checks the context associated with the session for compare-and-swap
        update revision number constraints. If one is found, this returns the
        instance that is constrained as well as the requested revision number
        to match.
        """
        criteria = getattr(session.info.get('using_context'), '_CONSTRAINT',
                           None)
        if not criteria:
            return None, None
        match = criteria['if_revision_match']
        mmap = standard_attr.get_standard_attr_resource_model_map()
        model = mmap.get(criteria['resource'])
        if not model:
            msg = _("Revision matching not supported for this resource")
            raise exc.BadRequest(resource=criteria['resource'], msg=msg)
        instance = self._find_instance_by_column_value(session, model, 'id',
                                                       criteria['resource_id'])
        return instance, match