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


Python exc.InvalidRequestError方法代码示例

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


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

示例1: assertRaiseloadWorked

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def assertRaiseloadWorked(self, entity, loaded, raiseloaded, unloaded):
        """ Test columns and their load state

            :param entity: the entity
            :param loaded: column names that are loaded and may be accessed without emitting any sql queries
            :param raiseloaded: column names that will raise an InvalidRequestError when accessed
            :param unloaded: column names that will emit 1 query when accessed
        """
        # loaded
        for name in loaded:
            with ExpectedQueryCounter(self.engine, 0,
                                      'Unexpected query while accessing column {}'.format(name)):
                getattr(entity, name)

        # raiseloaded
        for name in raiseloaded:
            with self.assertRaises(sa_exc.InvalidRequestError, msg='Exception was not raised when accessing attr `{}`'.format(name)):
                getattr(entity, name)

        # unloaded
        for name in unloaded:
            with ExpectedQueryCounter(self.engine, 1,
                                      'Expected one query while accessing column {}'.format(name)):
                getattr(entity, name) 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:26,代码来源:t_raiseload_col_test.py

示例2: create

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def create(cls, message, object, stage=u'Fetch', line=None):
        '''
        Helper function to create an error object and save it.
        '''
        err = cls(message=message, object=object,
                  stage=stage, line=line)
        try:
            err.save()
        except InvalidRequestError, e:
            # Clear any in-progress sqlalchemy transactions
            try:
                Session.rollback()
            except:
                pass
            try:
                Session.remove()
            except:
                pass
            err.save() 
开发者ID:italia,项目名称:daf-recipes,代码行数:21,代码来源:__init__.py

示例3: test_nested_self_raise

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def test_nested_self_raise(self, session, assert_session):
        @transaction(session)
        def create_user():
            user = User(username='test1', email='1@b.com', password='1')
            db.session.add(user)

        @transaction(session)
        def view_func():
            user = User(username='test2', email='2@b.com', password='1')
            db.session.add(user)
            create_user()

        if session.autocommit is False:
            msg = 'This transaction is closed'
            with pytest.raises(ResourceClosedError, match=msg):
                view_func()
        else:
            msg = r'A transaction is already begun.*'
            with pytest.raises(InvalidRequestError, match=msg):
                view_func()
        assert len(assert_session.query(User).all()) == 0 
开发者ID:TTWShell,项目名称:hobbit-core,代码行数:23,代码来源:test_db.py

示例4: reload_modules

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def reload_modules(module_name):
    """
    Reload all of fence's submodules.

    Use this after patching ``local_settings.py`` not existing, to make sure
    that nothing will remember that it existed.
    """
    # First we have to convince fence that ``local_settings.py`` does not
    # actually exist, even if it does. To do this, patch-delete the attribute
    # and reload all the fence modules.
    fence_submodules = [
        module for module in list(sys.modules.keys()) if module.startswith(module_name)
    ]
    for module in fence_submodules:
        if sys.modules[module]:
            # SQLAlchemy gets upset when a table is loaded twice, so ignore
            # that.
            try:
                importlib.reload(sys.modules[module])
            except InvalidRequestError:
                pass 
开发者ID:uc-cdis,项目名称:fence,代码行数:23,代码来源:test_import_fence.py

示例5: init_services

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def init_services(self):
        path_services = [self.path / "eNMS" / "services"]
        if self.settings["paths"]["custom_services"]:
            path_services.append(Path(self.settings["paths"]["custom_services"]))
        for path in path_services:
            for file in path.glob("**/*.py"):
                if "init" in str(file):
                    continue
                if not self.settings["app"]["create_examples"] and "examples" in str(
                    file
                ):
                    continue
                info(f"Loading service: {file}")
                spec = spec_from_file_location(str(file).split("/")[-1][:-3], str(file))
                try:
                    spec.loader.exec_module(module_from_spec(spec))
                except InvalidRequestError as exc:
                    error(f"Error loading custom service '{file}' ({str(exc)})") 
开发者ID:eNMS-automation,项目名称:eNMS,代码行数:20,代码来源:base.py

示例6: _handle_out_parameters

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def _handle_out_parameters(self):
        # if a single execute, check for outparams
        if len(self.compiled_parameters) == 1:
            quoted_bind_names = self.compiled._quoted_bind_names
            for bindparam in self.compiled.binds.values():
                if bindparam.isoutparam:
                    name = self.compiled.bind_names[bindparam]
                    type_impl = bindparam.type.dialect_impl(self.dialect)
                    if hasattr(type_impl, '_cx_oracle_var'):
                        self.out_parameters[name] = type_impl._cx_oracle_var(
                            self.dialect, self.cursor)
                    else:
                        dbtype = type_impl.get_dbapi_type(self.dialect.dbapi)
                        if dbtype is None:
                            raise exc.InvalidRequestError(
                                "Cannot create out parameter for parameter "
                                "%r - its type %r is not supported by"
                                " cx_oracle" %
                                (bindparam.key, bindparam.type)
                            )
                        self.out_parameters[name] = self.cursor.var(dbtype)
                    self.parameters[0][quoted_bind_names.get(name, name)] = \
                        self.out_parameters[name] 
开发者ID:yfauser,项目名称:planespotter,代码行数:25,代码来源:cx_oracle.py

示例7: tearDown

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def tearDown(self):
        """
        Tear down this test case by closing any existing database connection and deleting all of the
        objects that were marked for deletion.
        :return: None
        """
        if len(self.to_delete) > 0:
            for cur_delete in self.to_delete:
                try:
                    self.db_session.delete(cur_delete)
                except InvalidRequestError:
                    continue
            self.db_session.commit()
        if self._db_session is not None:
            self._db_session.close()
        if self._transaction is not None:
            self._transaction.rollback()
        if self._connection is not None:
            self._connection.close()
        super(BaseSqlalchemyTestCase, self).tearDown()

    # Protected Methods

    # Private Methods 
开发者ID:lavalamp-,项目名称:ws-backend-community,代码行数:26,代码来源:base.py

示例8: page_select_attack

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def page_select_attack(self, page_index):
        try:
            page_size = 10
            # num = 10*int(page) - 10
            logselect = self.session.query(OpencanaryLog).filter(
                OpencanaryLog.white == 2).order_by(
                    desc(OpencanaryLog.local_time),
                    OpencanaryLog.id).limit(page_size).offset(
                        (page_index - 1) * page_size)
            return logselect
        except InvalidRequestError:
            self.session.rollback()
        except Exception as e:
            print(e)
        finally:
            self.session.close()

    # 查询日志表白名单数据 
开发者ID:p1r06u3,项目名称:opencanary_web,代码行数:20,代码来源:LogOperate.py

示例9: page_select_white

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def page_select_white(self, page_index):
        try:
            page_size = 10
            # num = 10*int(page) - 10
            logselect = self.session.query(OpencanaryLog).filter(
                OpencanaryLog.white == 1).order_by(
                    desc(OpencanaryLog.local_time),
                    OpencanaryLog.id).limit(page_size).offset(
                        (page_index - 1) * page_size)
            return logselect
        except InvalidRequestError:
            self.session.rollback()
        except Exception as e:
            print(e)
        finally:
            self.session.close()

    # 查询当年每月攻击数量 
开发者ID:p1r06u3,项目名称:opencanary_web,代码行数:20,代码来源:LogOperate.py

示例10: white_select_num

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def white_select_num(self, months):
        try:
            white_num = self.session.query(
                extract('month', OpencanaryLog.local_time).label('month'),
                func.count('*').label('count')).filter(
                    extract('year', OpencanaryLog.local_time) == months,
                    OpencanaryLog.white == 1).group_by('month').all()
            return white_num
        except InvalidRequestError:
            self.session.rollback()
        except Exception as e:
            print(e)
        finally:
            self.session.close()

    # 查询各类攻击数量 
开发者ID:p1r06u3,项目名称:opencanary_web,代码行数:18,代码来源:LogOperate.py

示例11: pie_select_num

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def pie_select_num(self, years):
        try:
            pie_num = self.session.query(
                func.count(OpencanaryLog.logtype),
                OpencanaryLog.logtype).group_by(OpencanaryLog.logtype).filter(
                    extract('year', OpencanaryLog.local_time) == years,
                    OpencanaryLog.white == 2).all()
            return pie_num
        except InvalidRequestError:
            self.session.rollback()
        except Exception as e:
            print(e)
        finally:
            self.session.close()

    # 查询攻击数据总量 
开发者ID:p1r06u3,项目名称:opencanary_web,代码行数:18,代码来源:LogOperate.py

示例12: test_remove_not_listened

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def test_remove_not_listened(self):
        Target = self._fixture()

        m1 = Mock()

        t1 = Target()

        event.listen(t1, "event_one", m1, propagate=True)
        event.listen(t1, "event_three", m1)

        event.remove(t1, "event_one", m1)
        assert_raises_message(
            exc.InvalidRequestError,
            r"No listeners found for event <.*Target.*> / "
            r"'event_two' / <Mock.*> ",
            event.remove,
            t1,
            "event_two",
            m1,
        )

        event.remove(t1, "event_three", m1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_events.py

示例13: test_branch_nested_rollback

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def test_branch_nested_rollback(self, local_connection):
        connection = local_connection
        connection.begin()
        branched = connection.connect()
        assert branched.in_transaction()
        branched.execute(users.insert(), user_id=1, user_name="user1")
        nested = branched.begin()
        branched.execute(users.insert(), user_id=2, user_name="user2")
        nested.rollback()
        assert not connection.in_transaction()

        assert_raises_message(
            exc.InvalidRequestError,
            "This connection is on an inactive transaction.  Please",
            connection.exec_driver_sql,
            "select 1",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_transaction.py

示例14: test_inactive_due_to_subtransaction_no_commit

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def test_inactive_due_to_subtransaction_no_commit(self, local_connection):
        connection = local_connection
        trans = connection.begin()
        trans2 = connection.begin()
        trans2.rollback()
        assert_raises_message(
            exc.InvalidRequestError,
            "This connection is on an inactive transaction.  Please rollback",
            trans.commit,
        )

        trans.rollback()

        assert_raises_message(
            exc.InvalidRequestError,
            "This transaction is inactive",
            trans.commit,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_transaction.py

示例15: test_inactive_due_to_subtransaction_on_nested_no_commit

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InvalidRequestError [as 别名]
def test_inactive_due_to_subtransaction_on_nested_no_commit(
        self, local_connection
    ):
        connection = local_connection
        trans = connection.begin()

        nested = connection.begin_nested()

        trans2 = connection.begin()
        trans2.rollback()

        assert_raises_message(
            exc.InvalidRequestError,
            "This connection is on an inactive savepoint transaction.  "
            "Please rollback",
            nested.commit,
        )
        trans.commit()

        assert_raises_message(
            exc.InvalidRequestError,
            "This nested transaction is inactive",
            nested.commit,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_transaction.py


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