python类TransactionManagementError()的实例源码

schedulers.py 文件源码 项目:django-celery-beat 作者: celery 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def schedule_changed(self):
        try:
            # If MySQL is running with transaction isolation level
            # REPEATABLE-READ (default), then we won't see changes done by
            # other transactions until the current transaction is
            # committed (Issue #41).
            try:
                transaction.commit()
            except transaction.TransactionManagementError:
                pass  # not in transaction management.

            last, ts = self._last_timestamp, self.Changes.last_change()
        except DatabaseError as exc:
            logger.exception('Database gave error: %r', exc)
            return False
        try:
            if ts and ts > (last if last else ts):
                return True
        finally:
            self._last_timestamp = ts
        return False
orm.py 文件源码 项目:maas 作者: maas 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def validate_in_transaction(connection):
    """Ensure that `connection` is within a transaction.

    This only enquires as to Django's perspective on the situation. It does
    not actually check that the database agrees with Django.

    :raise TransactionManagementError: If no transaction is in progress.
    """
    if not in_transaction(connection):
        raise TransactionManagementError(
            # XXX: GavinPanella 2015-08-07 bug=1482563: This error message is
            # specific to lobjects, but this lives in a general utils module.
            "PostgreSQL's large object support demands that all interactions "
            "are done in a transaction. Further, lobject() has been known to "
            "segfault when used outside of a transaction. This assertion has "
            "prevented the use of lobject() outside of a transaction. Please "
            "investigate.")
test_events.py 文件源码 项目:thorn 作者: robinhood 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_on_signal__no_transaction(self, partial, on_commit):
        # test with signal_honor_transaction and not in transaction
        event = self.mock_event('x.y', sender_field=None)
        event.signal_honors_transaction = True
        event._on_signal = Mock(name='_on_signal')
        instance = self.Model()
        on_commit.side_effect = TransactionManagementError()
        assert django.TransactionManagementError is TransactionManagementError
        event.on_signal(instance, kw=1)
        partial.assert_called_once_with(event._on_signal, instance, {'kw': 1})
        on_commit.assert_called_once_with(partial())
        partial.return_value.assert_called_once_with()
django.py 文件源码 项目:thorn 作者: robinhood 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def on_commit(self, fun, *args, **kwargs):
        if args or kwargs:
            fun = partial(fun, *args, **kwargs)
        if on_commit is not None:
            try:
                return on_commit(fun)
            except TransactionManagementError:
                pass  # not in transaction management, execute now.
        return fun()
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_rollback(self):
        """
        Get the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        return self.needs_rollback
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 102 收藏 0 点赞 0 评论 0
def set_rollback(self, rollback):
        """
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        self.needs_rollback = rollback
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 82 收藏 0 点赞 0 评论 0
def validate_no_atomic_block(self):
        """
        Raise an error if an atomic block is active.
        """
        if self.in_atomic_block:
            raise TransactionManagementError(
                "This is forbidden when an 'atomic' block is active.")
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def validate_no_broken_transaction(self):
        if self.needs_rollback:
            raise TransactionManagementError(
                "An error occurred in the current transaction. You can't "
                "execute queries until the end of the 'atomic' block.")

    # ##### Foreign key constraints checks handling #####
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def on_commit(self, func):
        if self.in_atomic_block:
            # Transaction in progress; save for execution on commit.
            self.run_on_commit.append((set(self.savepoint_ids), func))
        elif not self.get_autocommit():
            raise TransactionManagementError('on_commit() cannot be used in manual transaction management')
        else:
            # No transaction in progress and in autocommit mode; execute
            # immediately.
            func()
tasks.py 文件源码 项目:videofront 作者: openfun 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def release_lock(name):
    """
    Release a lock for all. Note that the lock will be released even if it was
    never acquired.
    """
    # Note that in unit tests, and in case the wrapped code raises an
    # IntegrityError, releasing the cache will result in a
    # TransactionManagementError. This is because unit tests run inside atomic
    # blocks. We cannot execute queries inside an atomic block if a transaction
    # needs to be rollbacked.
    try:
        cache.delete(name)
    except TransactionManagementError:
        logger.error("Could not release lock %s", name)
base.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_rollback(self):
        """
        Get the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        return self.needs_rollback
base.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_rollback(self, rollback):
        """
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        self.needs_rollback = rollback
base.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def validate_no_atomic_block(self):
        """
        Raise an error if an atomic block is active.
        """
        if self.in_atomic_block:
            raise TransactionManagementError(
                "This is forbidden when an 'atomic' block is active.")
base.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def validate_no_broken_transaction(self):
        if self.needs_rollback:
            raise TransactionManagementError(
                "An error occurred in the current transaction. You can't "
                "execute queries until the end of the 'atomic' block.")

    # ##### Foreign key constraints checks handling #####
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 53 收藏 0 点赞 0 评论 0
def get_rollback(self):
        """
        Get the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        return self.needs_rollback
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set_rollback(self, rollback):
        """
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        self.needs_rollback = rollback
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def validate_no_atomic_block(self):
        """
        Raise an error if an atomic block is active.
        """
        if self.in_atomic_block:
            raise TransactionManagementError(
                "This is forbidden when an 'atomic' block is active.")
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def validate_no_broken_transaction(self):
        if self.needs_rollback:
            raise TransactionManagementError(
                "An error occurred in the current transaction. You can't "
                "execute queries until the end of the 'atomic' block.")

    # ##### Foreign key constraints checks handling #####
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def on_commit(self, func):
        if self.in_atomic_block:
            # Transaction in progress; save for execution on commit.
            self.run_on_commit.append((set(self.savepoint_ids), func))
        elif not self.get_autocommit():
            raise TransactionManagementError('on_commit() cannot be used in manual transaction management')
        else:
            # No transaction in progress and in autocommit mode; execute
            # immediately.
            func()
base.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_rollback(self):
        """
        Get the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        return self.needs_rollback
base.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_rollback(self, rollback):
        """
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        self.needs_rollback = rollback
base.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def validate_no_atomic_block(self):
        """
        Raise an error if an atomic block is active.
        """
        if self.in_atomic_block:
            raise TransactionManagementError(
                "This is forbidden when an 'atomic' block is active.")
base.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def validate_no_broken_transaction(self):
        if self.needs_rollback:
            raise TransactionManagementError(
                "An error occurred in the current transaction. You can't "
                "execute queries until the end of the 'atomic' block.")

    # ##### Foreign key constraints checks handling #####
base.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def on_commit(self, func):
        if self.in_atomic_block:
            # Transaction in progress; save for execution on commit.
            self.run_on_commit.append((set(self.savepoint_ids), func))
        elif not self.get_autocommit():
            raise TransactionManagementError('on_commit() cannot be used in manual transaction management')
        else:
            # No transaction in progress and in autocommit mode; execute
            # immediately.
            func()
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_rollback(self):
        """
        Get the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        return self.needs_rollback
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def set_rollback(self, rollback):
        """
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        """
        if not self.in_atomic_block:
            raise TransactionManagementError(
                "The rollback flag doesn't work outside of an 'atomic' block.")
        self.needs_rollback = rollback
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def validate_no_atomic_block(self):
        """
        Raise an error if an atomic block is active.
        """
        if self.in_atomic_block:
            raise TransactionManagementError(
                "This is forbidden when an 'atomic' block is active.")
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def validate_no_broken_transaction(self):
        if self.needs_rollback:
            raise TransactionManagementError(
                "An error occurred in the current transaction. You can't "
                "execute queries until the end of the 'atomic' block.")

    # ##### Foreign key constraints checks handling #####
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def on_commit(self, func):
        if self.in_atomic_block:
            # Transaction in progress; save for execution on commit.
            self.run_on_commit.append((set(self.savepoint_ids), func))
        elif not self.get_autocommit():
            raise TransactionManagementError('on_commit() cannot be used in manual transaction management')
        else:
            # No transaction in progress and in autocommit mode; execute
            # immediately.
            func()
0143_fill_project_orgs.py 文件源码 项目:Sentry 作者: NetEaseGame 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def atomic_save(model):
    try:
        with transaction.atomic():
            model.save()
    except transaction.TransactionManagementError:
        # sqlite isn't happy
        model.save()


问题


面经


文章

微信
公众号

扫码关注公众号