예제 #1
0
    def _perform_create(self, data, **kwargs):
        """Check for conflicts and create a new object

        Is is passed the data parsed by the marshmallow schema (it
        transform from raw post data to a JSON)
        """
        obj = self.model_class(**data)
        # assert not db.session.new
        try:
            db.session.add(obj)
            db.session.commit()
        except sqlalchemy.exc.IntegrityError as ex:
            if not is_unique_constraint_violation(ex):
                raise
            db.session.rollback()
            conflict_obj = get_conflict_object(db.session, obj, data)
            if conflict_obj:
                abort(409, ValidationError(
                    {
                        'message': 'Existing value',
                        'object': self._get_schema_class()().dump(
                            conflict_obj).data,
                    }
                ))
            else:
                raise
        return obj
예제 #2
0
    def _perform_create(self, data, workspace_name):
        assert not db.session.new
        workspace = self._get_workspace(workspace_name)
        obj = self.model_class(**data)
        obj.workspace = workspace
        # assert not db.session.new
        try:
            db.session.add(obj)
            db.session.commit()
        except sqlalchemy.exc.IntegrityError as ex:
            if not is_unique_constraint_violation(ex):
                raise
            db.session.rollback()
            workspace = self._get_workspace(workspace_name)
            conflict_obj = get_conflict_object(db.session, obj, data, workspace)
            if conflict_obj:
                abort(409, ValidationError(
                    {
                        'message': 'Existing value',
                        'object': self._get_schema_class()().dump(
                            conflict_obj).data,
                    }
                ))
            else:
                raise

        self._set_command_id(obj, True)
        return obj
예제 #3
0
파일: base.py 프로젝트: infobyte/faraday
    def _perform_create(self, data, workspace_name):
        assert not db.session.new
        workspace = self._get_workspace(workspace_name)
        obj = self.model_class(**data)
        obj.workspace = workspace
        # assert not db.session.new
        try:
            db.session.add(obj)
            db.session.commit()
        except sqlalchemy.exc.IntegrityError as ex:
            if not is_unique_constraint_violation(ex):
                raise
            db.session.rollback()
            workspace = self._get_workspace(workspace_name)
            conflict_obj = get_conflict_object(db.session, obj, data, workspace)
            if conflict_obj:
                flask.abort(409, ValidationError(
                    {
                        'message': 'Existing value',
                        'object': self._get_schema_class()().dump(
                            conflict_obj).data,
                    }
                ))
            else:
                raise

        self._set_command_id(obj, True)
        return obj
예제 #4
0
파일: base.py 프로젝트: infobyte/faraday
    def _perform_create(self, data, **kwargs):
        """Check for conflicts and create a new object

        Is is passed the data parsed by the marshmallow schema (it
        transform from raw post data to a JSON)
        """
        obj = self.model_class(**data)
        # assert not db.session.new
        try:
            db.session.add(obj)
            db.session.commit()
        except sqlalchemy.exc.IntegrityError as ex:
            if not is_unique_constraint_violation(ex):
                raise
            db.session.rollback()
            conflict_obj = get_conflict_object(db.session, obj, data)
            if conflict_obj:
                flask.abort(409, ValidationError(
                    {
                        'message': 'Existing value',
                        'object': self._get_schema_class()().dump(
                            conflict_obj).data,
                    }
                ))
            else:
                raise
        return obj
예제 #5
0
파일: base.py 프로젝트: x0james/faraday
 def _perform_update(self, object_id, obj, data, workspace_name=None):
     """Commit the SQLAlchemy session, check for updating conflicts"""
     try:
         db.session.add(obj)
         db.session.commit()
     except sqlalchemy.exc.IntegrityError as ex:
         if not is_unique_constraint_violation(ex):
             raise
         db.session.rollback()
         workspace = None
         if workspace_name:
             workspace = db.session.query(Workspace).filter_by(
                 name=workspace_name).first()
         conflict_obj = get_conflict_object(db.session, obj, data,
                                            workspace)
         if conflict_obj:
             flask.abort(
                 409,
                 ValidationError({
                     'message':
                     'Existing value',
                     'object':
                     self._get_schema_class()().dump(conflict_obj).data,
                 }))
         else:
             raise
     return obj
예제 #6
0
 def _perform_create(self, data, **kwargs):
     obj = self.model_class(**data)
     # assert not db.session.new
     try:
         db.session.add(obj)
         db.session.commit()
     except sqlalchemy.exc.IntegrityError as ex:
         if not is_unique_constraint_violation(ex):
             raise
         db.session.rollback()
         conflict_obj = get_conflict_object(db.session, obj, data)
         if conflict_obj:
             abort(409, ValidationError(
                 {
                     'message': 'Existing value',
                     'object': self._get_schema_class()().dump(
                         conflict_obj).data,
                 }
             ))
         else:
             raise
     return obj
예제 #7
0
파일: base.py 프로젝트: infobyte/faraday
 def _perform_update(self, object_id, obj, data, workspace_name=None):
     """Commit the SQLAlchemy session, check for updating conflicts"""
     try:
         db.session.add(obj)
         db.session.commit()
     except sqlalchemy.exc.IntegrityError as ex:
         if not is_unique_constraint_violation(ex):
             raise
         db.session.rollback()
         workspace = None
         if workspace_name:
             workspace = db.session.query(Workspace).filter_by(name=workspace_name).first()
         conflict_obj = get_conflict_object(db.session, obj, data, workspace)
         if conflict_obj:
             flask.abort(409, ValidationError(
                 {
                     'message': 'Existing value',
                     'object': self._get_schema_class()().dump(
                         conflict_obj).data,
                 }
             ))
         else:
             raise
     return obj