コード例 #1
0
ファイル: manager.py プロジェクト: TomNeyland/potion
    def update(self, item, changes, commit=True):
        session = self._get_session()
        actual_changes = {
            key: value for key, value in changes.items()
            if get_value(key, item, None) != value
        }

        try:
            before_update.send(self.resource, item=item, changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            if commit:
                session.commit()
        except IntegrityError as e:
            session.rollback()

            # XXX need some better way to detect postgres engine.
            if hasattr(e.orig, 'pgcode'):
                if e.orig.pgcode == '23505':  # duplicate key
                    raise DuplicateKey(detail=e.orig.diag.message_detail)
            raise

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #2
0
ファイル: manager.py プロジェクト: tpandit/potion
    def update(self, item, changes, commit=True):
        session = self._get_session()

        actual_changes = {
            key: value
            for key, value in changes.items()
            if self._is_change(get_value(key, item, None), value)
        }

        try:
            before_update.send(self.resource,
                               item=item,
                               changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            if commit:
                session.commit()
        except IntegrityError as e:
            session.rollback()

            # XXX need some better way to detect postgres engine.
            if hasattr(e.orig, 'pgcode'):
                if e.orig.pgcode == '23505':  # duplicate key
                    raise DuplicateKey(detail=e.orig.diag.message_detail)

            if current_app.debug:
                raise BackendConflict(debug_info=dict(exception_message=str(e),
                                                      statement=e.statement,
                                                      params=e.params))
            raise BackendConflict()

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #3
0
ファイル: manager.py プロジェクト: biosustain/potion
    def update(self, item, changes, commit=True):
        session = self._get_session()

        actual_changes = {
            key: value for key, value in changes.items()
            if self._is_change(get_value(key, item, None), value)
        }

        try:
            before_update.send(self.resource, item=item, changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            self.commit_or_flush(commit)
        except IntegrityError as e:
            session.rollback()

            # XXX need some better way to detect postgres engine.
            if hasattr(e.orig, 'pgcode'):
                if e.orig.pgcode == '23505':  # duplicate key
                    raise DuplicateKey(detail=e.orig.diag.message_detail)

            if current_app.debug:
                raise BackendConflict(debug_info=dict(exception_message=str(e), statement=e.statement, params=e.params))
            raise BackendConflict()

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #4
0
ファイル: manager.py プロジェクト: abbi031892/potion
    def update(self, item, changes, commit=True):
        session = self._get_session()
        actual_changes = {
            key: value
            for key, value in changes.items()
            if get_value(key, item, None) != value
        }

        try:
            before_update.send(self.resource,
                               item=item,
                               changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            if commit:
                session.commit()
        except IntegrityError as e:
            session.rollback()

            # XXX need some better way to detect postgres engine.
            if hasattr(e.orig, 'pgcode'):
                if e.orig.pgcode == '23505':  # duplicate key
                    raise DuplicateKey(detail=e.orig.diag.message_detail)
            raise

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #5
0
ファイル: manager.py プロジェクト: infarm/potion
    def update(self, item, changes):
        session = self._get_session()
        with session.begin_nested():
            actual_changes = {
                key: value
                for key, value in changes.items()
                if self._is_change(get_value(key, item, None), value)
            }
            before_update.send(self.resource, item=item, changes=actual_changes)
            try:
                for key, value in changes.items():
                    setattr(item, key, value)
                session.flush()
            except IntegrityError as exc:

                # XXX need some better way to detect postgres engine.
                if hasattr(exc.orig, 'pgcode'):
                    if exc.orig.pgcode == '23505':  # duplicate key
                        raise DuplicateKey(detail=exc.orig.diag.message_detail) from exc

                if current_app.debug:
                    raise BackendConflict(
                        debug_info=dict(
                            exception_message=str(exc),
                            statement=exc.statement,
                            params=exc.params,
                        )
                    ) from exc
                raise BackendConflict() from exc

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #6
0
ファイル: manager.py プロジェクト: biosustain/potion
    def update(self, item, changes, commit=True):
        actual_changes = {
            key: value for key, value in changes.items()
            if get_value(key, item, None) != value
            }

        try:
            before_update.send(self.resource, item=item, changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            if commit:
                item.save()
        except OperationError:
            raise

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item
コード例 #7
0
    def update(self, item, changes, commit=True):
        actual_changes = {
            key: value
            for key, value in changes.items()
            if get_value(key, item, None) != value
        }

        try:
            before_update.send(self.resource,
                               item=item,
                               changes=actual_changes)

            for key, value in changes.items():
                setattr(item, key, value)

            if commit:
                item.save()
        except OperationError:
            raise

        after_update.send(self.resource, item=item, changes=actual_changes)
        return item