sqlalchemy.exc.ArgumentError

Here are the examples of the python api sqlalchemy.exc.ArgumentError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

367 Examples 7

3 Source : base.py
with GNU General Public License v3.0
from Artikash

    def visit_extract(self, extract, **kw):
        try:
            return "CAST(STRFTIME('%s', %s) AS INTEGER)" % (
                self.extract_map[extract.field], self.process(extract.expr, **kw))
        except KeyError:
            raise exc.ArgumentError(
                "%s is not a valid extract argument." % extract.field)

    def limit_clause(self, select):

3 Source : schema.py
with GNU General Public License v3.0
from Artikash

    def __init__(self, arg, **kwargs):
        super(ColumnDefault, self).__init__(**kwargs)
        if isinstance(arg, FetchedValue):
            raise exc.ArgumentError(
                "ColumnDefault may not be a server-side default type.")
        if util.callable(arg):
            arg = self._maybe_wrap_callable(arg)
        self.arg = arg

    @util.memoized_property

3 Source : schema.py
with GNU General Public License v3.0
from Artikash

    def _check_ddl_on(self, on):
        if (on is not None and
            (not isinstance(on, (basestring, tuple, list, set)) and 
                    not util.callable(on))):
            raise exc.ArgumentError(
                "Expected the name of a database dialect, a tuple "
                "of names, or a callable for "
                "'on' criteria, got type '%s'." % type(on).__name__)

    def _should_execute(self, event, target, bind, **kw):

3 Source : schema.py
with GNU General Public License v3.0
from Artikash

def _to_schema_column(element):
   if hasattr(element, '__clause_element__'):
       element = element.__clause_element__()
   if not isinstance(element, Column):
       raise exc.ArgumentError("schema.Column object expected")
   return element

def _to_schema_column_or_string(element):

3 Source : expression.py
with GNU General Public License v3.0
from Artikash

def _no_literals(element):
    if hasattr(element, '__clause_element__'):
        return element.__clause_element__()
    elif not isinstance(element, Visitable):
        raise exc.ArgumentError("Ambiguous literal: %r.  Use the 'text()' "
                                "function to indicate a SQL expression "
                                "literal, or 'literal()' to indicate a "
                                "bound value." % element)
    else:
        return element

def _only_column_elements(element, name):

3 Source : expression.py
with GNU General Public License v3.0
from Artikash

def _only_column_elements(element, name):
    if hasattr(element, '__clause_element__'):
        element = element.__clause_element__()
    if not isinstance(element, ColumnElement):
        raise exc.ArgumentError("Column-based expression object expected for argument '%s'; "
                                "got: '%s', type %s" % (name, element, type(element)))
    return element

def _corresponding_column_or_error(fromclause, column,

3 Source : expression.py
with GNU General Public License v3.0
from Artikash

    def _params(self, unique, optionaldict, kwargs):
        if len(optionaldict) == 1:
            kwargs.update(optionaldict[0])
        elif len(optionaldict) > 1:
            raise exc.ArgumentError(
                "params() takes zero or one positional dictionary argument")

        def visit_bindparam(bind):
            if bind.key in kwargs:
                bind.value = kwargs[bind.key]
            if unique:
                bind._convert_to_unique()
        return cloned_traverse(self, {}, {'bindparam':visit_bindparam})

    def compare(self, other, **kw):

3 Source : expression.py
with GNU General Public License v3.0
from Artikash

    def __contains__(self, other):
        if not isinstance(other, basestring):
            raise exc.ArgumentError("__contains__ requires a string argument")
        return util.OrderedProperties.__contains__(self, other)

    def contains_column(self, col):

3 Source : util.py
with GNU General Public License v3.0
from Artikash

def assert_arg_type(arg, argtype, name):
    if isinstance(arg, argtype):
        return arg
    else:
        if isinstance(argtype, tuple):
            raise exc.ArgumentError(
                            "Argument '%s' is expected to be one of type %s, got '%s'" % 
                            (name, ' or '.join("'%s'" % a for a in argtype), type(arg)))
        else:
            raise exc.ArgumentError(
                            "Argument '%s' is expected to be of type '%s', got '%s'" % 
                            (name, argtype, type(arg)))

_creation_order = 1

3 Source : test_utils.py
with Apache License 2.0
from gethue

    def test_in(self):
        cc = sql.ColumnCollection()
        cc.add(sql.column("col1"))
        cc.add(sql.column("col2"))
        cc.add(sql.column("col3"))
        assert "col1" in cc
        assert "col2" in cc

        try:
            cc["col1"] in cc
            assert False
        except exc.ArgumentError as e:
            eq_(str(e), "__contains__ requires a string argument")

    def test_compare(self):

3 Source : test_types.py
with Apache License 2.0
from gethue

    def test_bitwise_required_for_empty(self):
        assert_raises_message(
            exc.ArgumentError,
            "Can't use the blank value '' in a SET without setting "
            "retrieve_as_bitwise=True",
            mysql.SET,
            "a",
            "b",
            "",
        )

    @testing.provide_metadata

3 Source : test_dialect.py
with Apache License 2.0
from gethue

    def test_executemany_wrong_flag_options(self):
        for opt in [1, True, "batch_insert"]:
            assert_raises_message(
                exc.ArgumentError,
                "Invalid value for 'executemany_mode': %r" % opt,
                engines.testing_engine,
                options={"executemany_mode": opt},
            )


class MiscBackendTest(

3 Source : test_transaction.py
with Apache License 2.0
from gethue

    def test_invalid_level(self):
        eng = testing_engine(options=dict(isolation_level="FOO"))
        assert_raises_message(
            exc.ArgumentError,
            "Invalid value '%s' for isolation_level. "
            "Valid isolation levels for %s are %s"
            % (
                "FOO",
                eng.dialect.name,
                ", ".join(eng.dialect._isolation_lookup),
            ),
            eng.connect,
        )

    def test_connection_invalidated(self):

3 Source : test_transaction.py
with Apache License 2.0
from gethue

    def test_per_statement_bzzt(self):
        assert_raises_message(
            exc.ArgumentError,
            r"'isolation_level' execution option may only be specified "
            r"on Connection.execution_options\(\), or "
            r"per-engine using the isolation_level "
            r"argument to create_engine\(\).",
            select([1]).execution_options,
            isolation_level=self._non_default_isolation_level(),
        )

    def test_per_engine(self):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_relationship_level_msg_for_invalid_callable(self):
        class A(Base):
            __tablename__ = "a"
            id = Column(Integer, primary_key=True)

        class B(Base):
            __tablename__ = "b"
            id = Column(Integer, primary_key=True)
            a_id = Column(Integer, ForeignKey("a.id"))
            a = relationship("a")

        assert_raises_message(
            sa.exc.ArgumentError,
            "relationship 'a' expects a class or a mapper "
            "argument .received: .*Table",
            configure_mappers,
        )

    def test_relationship_level_msg_for_invalid_object(self):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_relationship_level_msg_for_invalid_object(self):
        class A(Base):
            __tablename__ = "a"
            id = Column(Integer, primary_key=True)

        class B(Base):
            __tablename__ = "b"
            id = Column(Integer, primary_key=True)
            a_id = Column(Integer, ForeignKey("a.id"))
            a = relationship(A.__table__)

        assert_raises_message(
            sa.exc.ArgumentError,
            "relationship 'a' expects a class or a mapper "
            "argument .received: .*Table",
            configure_mappers,
        )

    def test_difficult_class(self):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_table_args_type(self):
        def err():
            class Foo1(Base):

                __tablename__ = "foo"
                __table_args__ = ForeignKeyConstraint(["id"], ["foo.id"])
                id = Column("id", Integer, primary_key=True)

        assert_raises_message(
            sa.exc.ArgumentError, "__table_args__ value must be a tuple, ", err
        )

    def test_table_args_none(self):

3 Source : test_inheritance.py
with Apache License 2.0
from gethue

    def test_single_no_special_cols(self):
        class Person(Base, fixtures.ComparableEntity):

            __tablename__ = "people"
            id = Column("id", Integer, primary_key=True)
            name = Column("name", String(50))
            discriminator = Column("type", String(50))
            __mapper_args__ = {"polymorphic_on": discriminator}

        def go():
            class Engineer(Person):

                __mapper_args__ = {"polymorphic_identity": "engineer"}
                primary_language = Column("primary_language", String(50))
                foo_bar = Column(Integer, primary_key=True)

        assert_raises_message(sa.exc.ArgumentError, "place primary key", go)

    def test_single_no_table_args(self):

3 Source : test_associationproxy.py
with Apache License 2.0
from gethue

    def test_filter_has_scalar_raises(self):
        User = self.classes.User
        assert_raises_message(
            exc.ArgumentError,
            r"Can't apply keyword arguments to column-targeted",
            User.singular_keyword.has,
            keyword="brown",
        )

    def test_filter_eq_chained_has_to_any(self):

3 Source : test_associationproxy.py
with Apache License 2.0
from gethue

    def test_has_criterion_nul(self):
        # but we don't allow that with any criterion...
        User = self.classes.User
        self.classes.Singular

        assert_raises_message(
            exc.ArgumentError,
            r"Non-empty has\(\) not allowed",
            User.singular_value.has,
            User.singular_value == "singular4",
        )

    def test_has_kwargs_nul(self):

3 Source : test_associationproxy.py
with Apache License 2.0
from gethue

    def test_has_kwargs_nul(self):
        # ... or kwargs
        User = self.classes.User
        self.classes.Singular

        assert_raises_message(
            exc.ArgumentError,
            r"Can't apply keyword arguments to column-targeted",
            User.singular_value.has,
            singular_value="singular4",
        )

    def test_filter_scalar_object_contains_fails_nul_nul(self):

3 Source : test_extendedattr.py
with Apache License 2.0
from gethue

    def test_unmapped_not_type_error(self):
        """extension version of the same test in test_mapper.

        fixes #3408
        """
        assert_raises_message(
            sa.exc.ArgumentError,
            "Class object expected, got '5'.",
            class_mapper,
            5,
        )

    def test_unmapped_not_type_error_iter_ok(self):

3 Source : test_extendedattr.py
with Apache License 2.0
from gethue

    def test_unmapped_not_type_error_iter_ok(self):
        """extension version of the same test in test_mapper.

        fixes #3408
        """
        assert_raises_message(
            sa.exc.ArgumentError,
            r"Class object expected, got '\(5, 6\)'.",
            class_mapper,
            (5, 6),
        )


class FinderTest(_ExtBase, fixtures.ORMTest):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_non_col_polymorphic_on(self):
        Parent = self.classes.Parent
        t2 = self.tables.t2
        assert_raises_message(
            sa_exc.ArgumentError,
            "Can't determine polymorphic_on "
            "value 'im not a column' - no "
            "attribute is mapped to this name.",
            mapper,
            Parent,
            t2,
            polymorphic_on="im not a column",
        )

    def test_polymorphic_on_non_expr_prop(self):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_polymorphic_on_non_expr_prop(self):
        t2 = self.tables.t2
        Parent = self.classes.Parent

        assert_raises_message(
            sa_exc.ArgumentError,
            "Only direct column-mapped property or "
            "SQL expression can be passed for polymorphic_on",
            mapper,
            Parent,
            t2,
            polymorphic_on=lambda: "hi",
            polymorphic_identity=0,
        )

    def test_polymorphic_on_not_present_col(self):

3 Source : test_basic.py
with Apache License 2.0
from gethue

    def test_polymorphic_on_synonym(self):
        t1 = self.tables.t1
        Parent = self.classes.Parent
        cprop = column_property(t1.c.x)
        assert_raises_message(
            sa_exc.ArgumentError,
            "Only direct column-mapped property or "
            "SQL expression can be passed for polymorphic_on",
            mapper,
            Parent,
            t1,
            properties={"discriminator": cprop, "discrim_syn": synonym(cprop)},
            polymorphic_identity="parent",
            polymorphic_on="discrim_syn",
        )

    def _roundtrip(

3 Source : test_cascade.py
with Apache License 2.0
from gethue

    def test_bad_cascade(self):
        addresses, Address = self.tables.addresses, self.classes.Address

        mapper(Address, addresses)
        assert_raises_message(
            sa_exc.ArgumentError,
            r"Invalid cascade option\(s\): 'fake', 'fake2'",
            relationship,
            Address,
            cascade="fake, all, delete-orphan, fake2",
        )

    def test_cascade_repr(self):

3 Source : test_collection.py
with Apache License 2.0
from gethue

    def test_column_mapped_assertions(self):
        assert_raises_message(
            sa_exc.ArgumentError,
            "Column-based expression object expected "
            "for argument 'mapping_spec'; got: 'a'",
            collections.column_mapped_collection,
            "a",
        )
        assert_raises_message(
            sa_exc.ArgumentError,
            "Column-based expression object expected "
            "for argument 'mapping_spec'; got: 'a'",
            collections.column_mapped_collection,
            text("a"),
        )

    def test_column_mapped_collection(self):

3 Source : test_default_strategies.py
with Apache License 2.0
from gethue

    def test_star_must_be_alone(self):
        sess = self._downgrade_fixture()
        User = self.classes.User
        opt = sa.orm.subqueryload("*", User.addresses)
        assert_raises_message(
            sa.exc.ArgumentError,
            "Wildcard token cannot be followed by another entity",
            sess.query(User).options,
            opt,
        )

    def test_global_star_ignored_no_entities_unbound(self):

3 Source : test_deprecations.py
with Apache License 2.0
from gethue

    def _assert_eager_with_entity_exception(
        self, entity_list, options, message
    ):
        assert_raises_message(
            sa.exc.ArgumentError,
            message,
            create_session().query(*entity_list).options,
            *options
        )

    def test_option_against_nonexistent_twolevel_all(self):

3 Source : test_deprecations.py
with Apache License 2.0
from gethue

    def test_unknown_legacy_lock_mode(self):
        User = self.classes.User
        sess = Session()
        with testing.expect_deprecated(
            r"The Query.with_lockmode\(\) method is deprecated"
        ):
            assert_raises_message(
                exc.ArgumentError,
                "Unknown with_lockmode argument: 'unknown_mode'",
                sess.query(User.id).with_lockmode,
                "unknown_mode",
            )


class InstrumentationTest(fixtures.ORMTest):

3 Source : test_events.py
with Apache License 2.0
from gethue

    def test_scoped_session_invalid_callable(self):
        from sqlalchemy.orm import scoped_session

        def my_listener_one(*arg, **kw):
            pass

        scope = scoped_session(lambda: Session())

        assert_raises_message(
            sa.exc.ArgumentError,
            "Session event listen on a scoped_session requires that its "
            "creation callable is associated with the Session class.",
            event.listen,
            scope,
            "before_flush",
            my_listener_one,
        )

    def test_scoped_session_invalid_class(self):

3 Source : test_froms.py
with Apache License 2.0
from gethue

    def test_select_entity_from_no_entities(self):
        User = self.classes.User
        sess = create_session()

        assert_raises_message(
            sa.exc.ArgumentError,
            r"A selectable \(FromClause\) instance is "
            "expected when the base alias is being set",
            sess.query(User).select_entity_from,
            User,
        )

    def test_select_from_no_aliasing(self):

3 Source : test_froms.py
with Apache License 2.0
from gethue

    def test_external_columns_bad(self):
        users, User = self.tables.users, self.classes.User

        assert_raises_message(
            sa_exc.ArgumentError,
            "not represented in the mapper's table",
            mapper,
            User,
            users,
            properties={"concat": (users.c.id * 2)},
        )
        clear_mappers()

    def test_external_columns(self):

3 Source : test_joins.py
with Apache License 2.0
from gethue

    def test_on_clause_no_right_side(self):
        User = self.classes.User
        Address = self.classes.Address
        sess = create_session()

        assert_raises_message(
            sa_exc.ArgumentError,
            "Expected mapped entity or selectable/table as join target",
            sess.query(User).join,
            User.id == Address.user_id,
        )

    def test_select_from(self):

3 Source : test_mapper.py
with Apache License 2.0
from gethue

    def test_column_not_present(self):
        users, addresses, User = (
            self.tables.users,
            self.tables.addresses,
            self.classes.User,
        )

        assert_raises_message(
            sa.exc.ArgumentError,
            "not represented in the mapper's table",
            mapper,
            User,
            users,
            properties={"foo": addresses.c.user_id},
        )

    def test_constructor_exc(self):

3 Source : test_mapper.py
with Apache License 2.0
from gethue

    def test_unmapped_not_type_error(self):
        assert_raises_message(
            sa.exc.ArgumentError,
            "Class object expected, got '5'.",
            class_mapper,
            5,
        )

    def test_unmapped_not_type_error_iter_ok(self):

3 Source : test_mapper.py
with Apache License 2.0
from gethue

    def test_unmapped_not_type_error_iter_ok(self):
        assert_raises_message(
            sa.exc.ArgumentError,
            r"Class object expected, got '\(5, 6\)'.",
            class_mapper,
            (5, 6),
        )

    def test_attribute_error_raised_class_mapper(self):

3 Source : test_mapper.py
with Apache License 2.0
from gethue

        def test_baseclass(self):
            ht1 = self.tables.ht1

            class OldStyle:
                pass

            assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1)

            assert_raises(sa.exc.ArgumentError, mapper, 123)

            class NoWeakrefSupport(str):
                pass

            # TODO: is weakref support detectable without an instance?
            # self.assertRaises(
            #  sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2)

    class _ValueBase(object):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_gen_path_invalid_from_col(self):
        User = self.classes.User

        result = Load(User)
        result.path = self._make_path_registry([User, "name"])
        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'name' of entity 'Mapper|User|users' does "
            "not refer to a mapped entity",
            result._generate_path,
            result.path,
            User.addresses,
            None,
            "relationship",
        )

    def test_gen_path_attr_entity_invalid_raiseerr(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_gen_path_attr_entity_invalid_raiseerr(self):
        User = self.classes.User
        Order = self.classes.Order

        result = Load(User)

        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'Order.items' does not link from element "
            "'Mapper|User|users'",
            result._generate_path,
            inspect(User)._path_registry,
            Order.items,
            None,
            "relationship",
        )

    def test_gen_path_attr_entity_invalid_noraiseerr(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def _assert_eager_with_entity_exception(
        self, entity_list, options, message
    ):
        assert_raises_message(
            sa.exc.ArgumentError,
            message,
            create_session().query(*entity_list).options,
            *options
        )

    def _assert_eager_with_just_column_exception(

3 Source : test_options.py
with Apache License 2.0
from gethue

    def _assert_eager_with_just_column_exception(
        self, column, eager_option, message
    ):
        assert_raises_message(
            sa.exc.ArgumentError,
            message,
            create_session().query(column).options,
            joinedload(eager_option),
        )


class OptionsNoPropTestInh(_Polymorphic):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_missing_attr_wpoly_subclasss(self):
        s = Session()

        wp = with_polymorphic(Person, [Manager], flat=True)

        assert_raises_message(
            sa.exc.ArgumentError,
            r'Mapped attribute "Manager.status" does not apply to any of '
            r"the root entities in this query, e.g. "
            r"with_polymorphic\(Person, \[Manager\]\).",
            s.query(wp).options,
            load_only(Manager.status),
        )

    def test_missing_attr_of_type_subclass(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_missing_attr_of_type_subclass(self):
        s = Session()

        assert_raises_message(
            sa.exc.ArgumentError,
            r'Attribute "Manager.manager_name" does not link from element '
            r'"with_polymorphic\(Person, \[Engineer\]\)".$',
            s.query(Company).options,
            joinedload(Company.employees.of_type(Engineer)).load_only(
                Manager.manager_name
            ),
        )

    def test_missing_attr_of_type_subclass_name_matches(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_missing_attr_of_type_subclass_name_matches(self):
        s = Session()

        # the name "status" is present on Engineer also, make sure
        # that doesn't get mixed up here
        assert_raises_message(
            sa.exc.ArgumentError,
            r'Attribute "Manager.status" does not link from element '
            r'"with_polymorphic\(Person, \[Engineer\]\)".$',
            s.query(Company).options,
            joinedload(Company.employees.of_type(Engineer)).load_only(
                Manager.status
            ),
        )

    def test_missing_str_attr_of_type_subclass(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_missing_str_attr_of_type_subclass(self):
        s = Session()

        assert_raises_message(
            sa.exc.ArgumentError,
            r'Can\'t find property named "manager_name" on '
            r"mapped class Engineer->engineers in this Query.$",
            s.query(Company).options,
            joinedload(Company.employees.of_type(Engineer)).load_only(
                "manager_name"
            ),
        )

    def test_missing_attr_of_type_wpoly_subclass(self):

3 Source : test_options.py
with Apache License 2.0
from gethue

    def test_missing_attr_of_type_wpoly_subclass(self):
        s = Session()

        wp = with_polymorphic(Person, [Manager], flat=True)

        assert_raises_message(
            sa.exc.ArgumentError,
            r'Attribute "Manager.manager_name" does not link from '
            r'element "with_polymorphic\(Person, \[Manager\]\)".$',
            s.query(Company).options,
            joinedload(Company.employees.of_type(wp)).load_only(
                Manager.manager_name
            ),
        )

    def test_missing_attr_is_missing_of_type_for_alias(self):

3 Source : test_query.py
with Apache License 2.0
from gethue

    def test_invalid_select_from(self):
        User = self.classes.User

        s = create_session()
        q = s.query(User)
        assert_raises(sa_exc.ArgumentError, q.select_from, User.id == 5)
        assert_raises(sa_exc.ArgumentError, q.select_from, User.id)

    def test_invalid_from_statement(self):

3 Source : test_query.py
with Apache License 2.0
from gethue

    def test_invalid_from_statement(self):
        User, addresses, users = (
            self.classes.User,
            self.tables.addresses,
            self.tables.users,
        )

        s = create_session()
        q = s.query(User)
        assert_raises(sa_exc.ArgumentError, q.from_statement, User.id == 5)
        assert_raises(
            sa_exc.ArgumentError, q.from_statement, users.join(addresses)
        )

    def test_invalid_column(self):

See More Examples