当前位置: 首页>>代码示例>>Python>>正文


Python exc.StaleDataError方法代码示例

本文整理汇总了Python中sqlalchemy.orm.exc.StaleDataError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.StaleDataError方法的具体用法?Python exc.StaleDataError怎么用?Python exc.StaleDataError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.orm.exc的用法示例。


在下文中一共展示了exc.StaleDataError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_w_mapper_versioning

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_w_mapper_versioning(self):
        class SomeClass(Versioned, self.Base, ComparableEntity):
            __tablename__ = "sometable"
            use_mapper_versioning = True

            id = Column(Integer, primary_key=True)
            name = Column(String(50))

        self.create_tables()
        sess = self.session
        sc = SomeClass(name="sc1")
        sess.add(sc)
        sess.commit()

        s2 = Session(sess.bind)
        sc2 = s2.query(SomeClass).first()
        sc2.name = "sc1modified"

        sc.name = "sc1modified_again"
        sess.commit()

        eq_(sc.version, 2)

        assert_raises(orm_exc.StaleDataError, s2.flush) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_versioning.py

示例2: remove_current_rooms_for_user

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def remove_current_rooms_for_user(self, user_id):
        @with_session
        def remove(room_sids: dict, session=None) -> None:

            for i in range(3):
                try:
                    self._remove_current_rooms_for_user(user_id, room_sids, session)
                    return
                except StaleDataError as e:
                    logger.warning('stale data when removing current rooms for user, attempt {}/2: {}'.format(
                        str(i), str(e)
                    ))
            logger.error('got stale data after 3 retries, giving up')

        sids_to_rooms = self.get_rooms_with_sid(user_id)
        room_to_sids = dict()
        for sid, room in sids_to_rooms.items():
            if room not in room_to_sids:
                room_to_sids[room] = set()
            room_to_sids[room].add(sid)

        remove(room_to_sids) 
开发者ID:thenetcircle,项目名称:dino,代码行数:24,代码来源:handler.py

示例3: test_merge_incorrect_version

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_merge_incorrect_version(self):
        Foo = self.classes.Foo

        s1 = self._fixture()
        f1 = Foo(value="f1")
        s1.add(f1)
        s1.commit()

        f1.value = "f2"
        with conditional_sane_rowcount_warnings(
            update=True, only_returning=True
        ):
            s1.commit()

        f2 = Foo(id=f1.id, value="f3", version_id=1)
        assert_raises_message(
            orm_exc.StaleDataError,
            "Version id '1' on merged state "
            "<Foo at .*?> does not match existing version '2'. "
            "Leave the version attribute unset when "
            "merging to update the most recent version.",
            s1.merge,
            f2,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_versioning.py

示例4: test_o2m_post_update_version_assert

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_o2m_post_update_version_assert(self):
        Node = self.classes.Node
        s, n1, n2 = self._fixture(o2m=True, post_update=True)

        n1.related.append(n2)

        # outwit the database transaction isolation and SQLA's
        # expiration at the same time by using different Session on
        # same transaction
        s2 = Session(bind=s.connection(mapper=Node))
        s2.query(Node).filter(Node.id == n2.id).update({"version_id": 3})
        s2.commit()

        assert_raises_message(
            orm_exc.StaleDataError,
            "UPDATE statement on table 'node' expected to "
            r"update 1 row\(s\); 0 were matched.",
            s.flush,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_versioning.py

示例5: test_concurrent_mod_err_expire_on_commit

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_concurrent_mod_err_expire_on_commit(self):
        sess = self._fixture()

        f1 = self.classes.Foo(value="f1")
        sess.add(f1)
        sess.commit()

        f1.value

        s2 = Session()
        f2 = s2.query(self.classes.Foo).first()
        f2.value = "f2"
        s2.commit()

        f1.value = "f3"

        assert_raises_message(
            orm.exc.StaleDataError,
            r"UPDATE statement on table 'version_table' expected to "
            r"update 1 row\(s\); 0 were matched.",
            sess.commit,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_versioning.py

示例6: test_concurrent_mod_err_noexpire_on_commit

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_concurrent_mod_err_noexpire_on_commit(self):
        sess = self._fixture(expire_on_commit=False)

        f1 = self.classes.Foo(value="f1")
        sess.add(f1)
        sess.commit()

        # here, we're not expired overall, so no load occurs and we
        # stay without a version id, unless we've emitted
        # a SELECT for it within the flush.
        f1.value

        s2 = Session(expire_on_commit=False)
        f2 = s2.query(self.classes.Foo).first()
        f2.value = "f2"
        s2.commit()

        f1.value = "f3"

        assert_raises_message(
            orm.exc.StaleDataError,
            r"UPDATE statement on table 'version_table' expected to "
            r"update 1 row\(s\); 0 were matched.",
            sess.commit,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_versioning.py

示例7: test_stale_state_negative

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_stale_state_negative(self):
        User = self.classes.User
        s, u1, a1 = self._fixture()

        u2 = User(addresses=[a1])
        s.add(u2)
        s.flush()
        s._expunge_states([attributes.instance_state(u2)])
        del u2
        gc_collect()

        assert_raises_message(
            orm_exc.StaleDataError,
            "can't be sure this is the most recent parent.",
            u1.addresses.remove,
            a1,
        )

        s.flush()
        self._assert_hasparent(a1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_hasparent.py

示例8: test_update_single_missing

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_update_single_missing(self):
        Parent, Child = self._fixture()
        sess = Session()
        p1 = Parent(id=1, data=2)
        sess.add(p1)
        sess.flush()

        sess.execute(self.tables.parent.delete())

        p1.data = 3
        assert_raises_message(
            orm_exc.StaleDataError,
            r"UPDATE statement on table 'parent' expected to "
            r"update 1 row\(s\); 0 were matched.",
            sess.flush,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_unitofworkv2.py

示例9: test_update_single_broken_multi_rowcount_still_raises

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def test_update_single_broken_multi_rowcount_still_raises(self):
        # raise occurs for single row UPDATE that misses even if
        # supports_sane_multi_rowcount is False
        Parent, Child = self._fixture()
        sess = Session()
        p1 = Parent(id=1, data=2, child=None)
        sess.add(p1)
        sess.flush()

        sess.execute(self.tables.parent.delete())
        p1.data = 3

        with patch.object(
            config.db.dialect, "supports_sane_multi_rowcount", False
        ):
            assert_raises_message(
                orm_exc.StaleDataError,
                r"UPDATE statement on table 'parent' expected to "
                r"update 1 row\(s\); 0 were matched.",
                sess.flush,
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_unitofworkv2.py

示例10: process_build

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def process_build(self, sack, build_group, build, brs):
        """
        Processes single build in given sack.
        Commits the transaction.
        """
        self.log.info("Processing %s", build)
        try:
            resolved, _, installs = self.resolve_dependencies(sack, brs, build_group)
            if not resolved:
                self.process_unresolved_build(build)
            else:
                self.process_resolved_build(build, installs)
            self.db.commit()
        except (StaleDataError, ObjectDeletedError):
            # build deleted concurrently, can be skipped
            self.db.rollback() 
开发者ID:fedora-infra,项目名称:koschei,代码行数:18,代码来源:build_resolver.py

示例11: poll_builds

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def poll_builds(self):
        self.log.info('Polling running Koji tasks...')
        running_builds = self.db.query(Build)\
                                .filter_by(state=Build.RUNNING)

        infos = itercall(self.session.koji('primary'), running_builds,
                         lambda k, b: k.getTaskInfo(b.task_id))

        for task_info, build in zip(infos, running_builds):
            try:
                name = build.package.name
                self.log.info('Polling task {id} ({name}): task_info={info}'
                              .format(id=build.task_id, name=name,
                                      info=task_info))
                state = koji.TASK_STATES[task_info['state']]
                backend.update_build_state(self.session, build, state)
            except (StaleDataError, ObjectDeletedError):
                # build was deleted concurrently
                self.db.rollback()
                continue 
开发者ID:fedora-infra,项目名称:koschei,代码行数:22,代码来源:polling.py

示例12: set_user_invisible

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def set_user_invisible(self, user_id: str, is_offline=False) -> None:
        @with_session
        def _set_user_invisible(session=None):
            user_status = session.query(UserStatus).filter(UserStatus.uuid == user_id).first()
            if user_status is None:
                user_status = UserStatus()
                user_status.uuid = user_id

            user_status.status = UserKeys.STATUS_INVISIBLE
            session.add(user_status)
            session.commit()

        if is_offline:
            self.env.cache.set_user_status_invisible(user_id)
        else:
            self._set_last_online(user_id)
            self.env.cache.set_user_invisible(user_id)

        try:
            _set_user_invisible()
        except (IntegrityError, StaleDataError) as e:
            logger.warning('could not set user %s invisible, will try again: %s' % (user_id, str(e)))
            try:
                _set_user_invisible()
            except (IntegrityError, StaleDataError) as e:
                logger.error('could not set user %s invisible second time, logging to sentry: %s' % (user_id, str(e)))
                self.env.capture_exception(sys.exc_info())
            except Exception as e:
                logger.error('other error when trying to set user %s invisible second try: %s' % (user_id, str(e)))
                logger.exception(traceback.format_exc())
                self.env.capture_exception(sys.exc_info()) 
开发者ID:thenetcircle,项目名称:dino,代码行数:33,代码来源:handler.py

示例13: set_user_offline

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def set_user_offline(self, user_id: str) -> None:
        @with_session
        def _set_user_offline(session=None):
            status = session.query(UserStatus).filter(UserStatus.uuid == user_id).first()
            if status is None:
                logger.warning('no UserStatus found in db for user ID %s' % user_id)
                return
            session.delete(status)
            session.commit()

        logger.debug('setting user %s as offline in cache' % user_id)
        self.env.cache.set_user_offline(user_id)

        try:
            self._set_last_online(user_id)
        except Exception as e:
            logger.error('could not set last_online in db for user {}: {}'.format(user_id, str(e)))
            logger.exception(traceback.format_exc())
            self.env.capture_exception(sys.exc_info())

        try:
            _set_user_offline()
        except (IntegrityError, StaleDataError) as e:
            logger.warning('could not set user %s offline, will try again: %s' % (user_id, str(e)))
            try:
                _set_user_offline()
            except (IntegrityError, StaleDataError) as e:
                logger.error('could not set user %s offline second time, logging to sentry: %s' % (user_id, str(e)))
                self.env.capture_exception(sys.exc_info())
            except Exception as e:
                logger.error('other error when trying to set user %s offline second try: %s' % (user_id, str(e)))
                logger.exception(traceback.format_exc())
                self.env.capture_exception(sys.exc_info()) 
开发者ID:thenetcircle,项目名称:dino,代码行数:35,代码来源:handler.py

示例14: set_user_online

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def set_user_online(self, user_id: str) -> None:
        @with_session
        def _set_user_online(session=None):
            user_status = session.query(UserStatus).filter(UserStatus.uuid == user_id).first()
            if user_status is None:
                user_status = UserStatus()
                user_status.uuid = user_id
                session.add(user_status)

            user_status.status = UserKeys.STATUS_AVAILABLE
            session.commit()

        self.env.cache.set_user_online(user_id)

        try:
            _set_user_online()
        except (IntegrityError, StaleDataError) as e:
            logger.warning('could not set user %s online, will try again: %s' % (user_id, str(e)))
            try:
                _set_user_online()
            except (IntegrityError, StaleDataError) as e:
                logger.error('could not set user %s online second time, logging to sentry: %s' % (user_id, str(e)))
                self.env.capture_exception(sys.exc_info())
            except Exception as e:
                logger.error('other error when trying to set user %s online second try: %s' % (user_id, str(e)))
                logger.exception(traceback.format_exc())
                self.env.capture_exception(sys.exc_info()) 
开发者ID:thenetcircle,项目名称:dino,代码行数:29,代码来源:handler.py

示例15: _remove_current_rooms_for_user

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import StaleDataError [as 别名]
def _remove_current_rooms_for_user(self, user_id: str, room_sids: dict, session):
        user = session.query(Users).filter(Users.uuid == user_id).first()
        if user is None:
            return

        rooms = session.query(Rooms)\
            .join(Rooms.users)\
            .filter(Users.uuid == user_id)\
            .all()

        if rooms is None or len(rooms) == 0:
            return

        for room in rooms:
            # have other sessions in the room
            if room.uuid in room_sids and len(room_sids[room.uuid]) > 0:
                continue

            try:
                room.users.remove(user)
            except ValueError:
                # happens if the user already left a room
                pass

        try:
            session.commit()
        except StaleDataError:
            # might have just been removed by another node
            session.rollback()

        self.env.cache.remove_rooms_for_user(user_id) 
开发者ID:thenetcircle,项目名称:dino,代码行数:33,代码来源:handler.py


注:本文中的sqlalchemy.orm.exc.StaleDataError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。