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


Python exc.ObjectDeletedError方法代码示例

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


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

示例1: remove_metadata_descriptor

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def remove_metadata_descriptor(metadata_descriptor_id):
    """
    Delete metadata descriptor and related informations.
    """
    descriptor = get_metadata_descriptor_raw(metadata_descriptor_id)
    entities = Entity.get_all_by(project_id=descriptor.project_id)
    for entity in entities:
        metadata = fields.serialize_value(entity.data)
        if metadata is not None:
            metadata.pop(descriptor.field_name, None)
            entity.update({"data": metadata})
    try:
        descriptor.delete()
    except ObjectDeletedError:
        pass
    events.emit(
        "metadata-descriptor:delete",
        {"metadata_descriptor_id": str(descriptor.id)},
    )
    clear_project_cache(str(descriptor.project_id))
    return descriptor.serialize() 
开发者ID:cgwire,项目名称:zou,代码行数:23,代码来源:projects_service.py

示例2: process_build

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [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

示例3: poll_builds

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [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

示例4: test_threads_only_deleted_when_no_messages_left

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_threads_only_deleted_when_no_messages_left(db, default_account,
                                                    default_namespace,
                                                    marked_deleted_message,
                                                    thread, folder):
    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=0)
    # Add another message onto the thread
    add_fake_message(db.session, default_namespace.id, thread)

    handler.check(marked_deleted_message.deleted_at + timedelta(seconds=1))
    db.session.expire_all()
    # Check that the orphaned message was deleted.
    with pytest.raises(ObjectDeletedError):
        marked_deleted_message.id
    # Would raise ObjectDeletedError if thread was deleted.
    thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:21,代码来源:test_delete_handling.py

示例5: device

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def device(session, device_data=None):
    now = datetime.now()
    device_data = {'ip_addr': '1.2.3.4',
                   'os_name': 'NXOS',
                   'created_at': now,
                   'updated_at': now,
                   'hw_model': 'Supercool9000',
                   'message': 'device added',
                   'os_version': '1.0.0a',
                   'serial_number': '1234567890',
                   'state': 'excellent',
                   'finally_script': 'finally',
                   'image_name': '1.0.1b',
                   'facts': '{"mac_address": "00112233445566"}'
                   }

    device = models.Device(**device_data)
    session.add(device)
    session.commit()

    # Have to convert datetime object to string because that's what sqlite3 does. Also have to add '+00:00'
    device_data['created_at'] = now.isoformat() + '+00:00'
    device_data['updated_at'] = now.isoformat() + '+00:00'

    yield device_data

    # Teardown code
    try:
        session.delete(device)
        session.commit()
    except ObjectDeletedError:
        pass 
开发者ID:Apstra,项目名称:aeon-ztps,代码行数:34,代码来源:conftest.py

示例6: build

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def build(self):
        try:
            # if self.fast_check():
            #     return

            self.auxiliary = {'time': now()}

            self.create_base()

            self.process_stop_tasks()

            self.process_start_dags()

            self.process_parent_tasks()

            self.load_tasks()

            self.load_computers()

            self.process_tasks()

            self.write_auxiliary()

        except ObjectDeletedError:
            pass
        except Exception as e:
            if Session.sqlalchemy_error(e):
                Session.cleanup(key='SupervisorBuilder')
                self.session = Session.create_session(key='SupervisorBuilder')
                self.logger = create_logger(self.session, 'SupervisorBuilder')

            self.logger.error(traceback.format_exc(), ComponentType.Supervisor) 
开发者ID:lightforever,项目名称:mlcomp,代码行数:34,代码来源:supervisor.py

示例7: test_exceptions

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_exceptions(self):
        class Foo(object):
            pass

        users = self.tables.users
        mapper(User, users)

        for sa_exc in (
            orm_exc.UnmappedInstanceError(Foo()),
            orm_exc.UnmappedClassError(Foo),
            orm_exc.ObjectDeletedError(attributes.instance_state(User())),
        ):
            for loads, dumps in picklers():
                repickled = loads(dumps(sa_exc))
                eq_(repickled.args[0], sa_exc.args[0]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:17,代码来源:test_pickled.py

示例8: test_generic_flags_refresh_expunges_transient_uids

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_generic_flags_refresh_expunges_transient_uids(
        db, generic_account, inbox_folder, mock_imapclient, monkeypatch):
    # Check that we delete UIDs which are synced but quickly deleted, so never
    # show up in flags refresh.
    uid_dict = uids.example()
    mock_imapclient.add_folder_data(inbox_folder.name, uid_dict)
    inbox_folder.imapfolderinfo = ImapFolderInfo(account=generic_account,
                                                 uidvalidity=1,
                                                 uidnext=1)
    db.session.commit()
    folder_sync_engine = FolderSyncEngine(generic_account.id,
                                          generic_account.namespace.id,
                                          inbox_folder.name,
                                          generic_account.email_address,
                                          'custom',
                                          BoundedSemaphore(1))
    folder_sync_engine.initial_sync()
    # Don't sleep at the end of poll_impl before returning.
    folder_sync_engine.poll_frequency = 0
    folder_sync_engine.poll_impl()
    msg = db.session.query(Message).filter_by(
        namespace_id=generic_account.namespace.id).first()
    transient_uid = ImapUid(folder=inbox_folder, account=generic_account,
                            message=msg, msg_uid=max(uid_dict) + 1)
    db.session.add(transient_uid)
    db.session.commit()
    folder_sync_engine.last_slow_refresh = None
    folder_sync_engine.poll_impl()
    with pytest.raises(ObjectDeletedError):
        transient_uid.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:32,代码来源:test_folder_sync.py

示例9: test_drafts_deleted_synchronously

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_drafts_deleted_synchronously(db, default_account, thread, message,
                                      imapuid, folder):
    message.is_draft = True
    db.session.commit()
    msg_uid = imapuid.msg_uid
    remove_deleted_uids(default_account.id, folder.id, [msg_uid])
    db.session.expire_all()
    with pytest.raises(ObjectDeletedError):
        message.id
    with pytest.raises(ObjectDeletedError):
        thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:13,代码来源:test_delete_handling.py

示例10: test_deletion_with_short_ttl

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_deletion_with_short_ttl(db, default_account, default_namespace,
                                 marked_deleted_message, thread, folder):
    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=0)
    handler.check(marked_deleted_message.deleted_at + timedelta(seconds=1))
    db.session.expire_all()
    # Check that objects were actually deleted
    with pytest.raises(ObjectDeletedError):
        marked_deleted_message.id
    with pytest.raises(ObjectDeletedError):
        thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:16,代码来源:test_delete_handling.py

示例11: test_deletion_deferred_with_longer_ttl

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_deletion_deferred_with_longer_ttl(db, default_account,
                                           default_namespace,
                                           marked_deleted_message, thread,
                                           folder):
    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=5)
    db.session.commit()

    handler.check(marked_deleted_message.deleted_at + timedelta(seconds=1))
    # Would raise ObjectDeletedError if objects were deleted
    marked_deleted_message.id
    thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:17,代码来源:test_delete_handling.py

示例12: test_deletion_with_short_ttl

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_deletion_with_short_ttl(db, default_account, default_namespace,
                                 marked_deleted_message, thread, folder):
    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=0, thread_ttl=0)
    handler.check(marked_deleted_message.deleted_at + timedelta(seconds=1))
    handler.gc_deleted_threads(thread.deleted_at + timedelta(seconds=1))
    db.session.expire_all()
    # Check that objects were actually deleted
    with pytest.raises(ObjectDeletedError):
        marked_deleted_message.id
    with pytest.raises(ObjectDeletedError):
        thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:17,代码来源:test_delete_handling.py

示例13: test_thread_deletion_with_short_ttl

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def test_thread_deletion_with_short_ttl(db, default_account, default_namespace,
                                        marked_deleted_message, thread, folder):
    handler = DeleteHandler(account_id=default_account.id,
                            namespace_id=default_namespace.id,
                            provider_name=default_account.provider,
                            uid_accessor=lambda m: m.imapuids,
                            message_ttl=0, thread_ttl=120)

    delete_time = marked_deleted_message.deleted_at
    handler.check(delete_time + timedelta(seconds=1))
    handler.gc_deleted_threads(delete_time + timedelta(seconds=1))
    db.session.expire_all()

    with pytest.raises(ObjectDeletedError):
        marked_deleted_message.id
    thread.id
    assert thread.deleted_at is not None

    handler.check(thread.deleted_at + timedelta(seconds=121))
    handler.gc_deleted_threads(thread.deleted_at + timedelta(seconds=121))
    db.session.expire_all()

    with pytest.raises(ObjectDeletedError):
        marked_deleted_message.id
    with pytest.raises(ObjectDeletedError):
        thread.id 
开发者ID:nylas,项目名称:sync-engine,代码行数:28,代码来源:test_delete_handling.py

示例14: message_update_job

# 需要导入模块: from sqlalchemy.orm import exc [as 别名]
# 或者: from sqlalchemy.orm.exc import ObjectDeletedError [as 别名]
def message_update_job(context, session):
    """Update all messages if necessary."""
    try:
        context.job.enabled = False
        now = datetime.now()

        update_count = session.query(Update).filter(Update.next_update <= now).count()

        while update_count > 0:
            updates = (
                session.query(Update)
                .filter(Update.next_update <= now)
                .options(joinedload(Update.poll))
                .order_by(Update.next_update.asc())
                .limit(50)
                .all()
            )

            for update in updates:
                try:
                    send_updates(session, context.bot, update.poll, show_warning=True)
                    session.delete(update)
                    session.commit()
                except ObjectDeletedError:
                    # The update has already been handled somewhere else.
                    # This could be either a job or a person that voted in this very moment
                    session.rollback()
                except RetryAfter as e:
                    # Schedule an update after the RetryAfter timeout + 1 second buffer
                    update.next_update = now + timedelta(seconds=int(e.retry_after) + 1)
                    try:
                        session.commit()
                    except StaleDataError:
                        # The update has already been handled somewhere else
                        session.rollback()

            # Update the count again.
            # Updates can be removed by normal operation as well
            update_count = (
                session.query(Update).filter(Update.next_update <= now).count()
            )

    except Exception as e:
        raise e

    finally:
        context.job.enabled = True
        session.close() 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:50,代码来源:job.py


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