Python sqlalchemy.exc.SAWarning() Examples

The following are 30 code examples of sqlalchemy.exc.SAWarning(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.exc , or try the search function .
Example #1
Source File: test_versioning.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_mismatch_version_col_warning(self):
        Base, sub, base, Sub = (
            self.classes.Base,
            self.tables.sub,
            self.tables.base,
            self.classes.Sub,
        )

        mapper(Base, base, version_id_col=base.c.version_id)

        assert_raises_message(
            exc.SAWarning,
            "Inheriting version_id_col 'version_id' does not "
            "match inherited version_id_col 'version_id' and will not "
            "automatically populate the inherited versioning column. "
            "version_id_col should only be specified on "
            "the base-most mapper that includes versioning.",
            mapper,
            Sub,
            sub,
            inherits=Base,
            version_id_col=sub.c.version_id,
        ) 
Example #2
Source File: assertions.py    From android_universal with MIT License 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, assert_=False, *messages):
            return fn(*args, **kw)

    return decorate 
Example #3
Source File: assertions.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def emits_warning_on(db, *warnings):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().
    """
    spec = db_spec(db)

    @decorator
    def decorate(fn, *args, **kw):
        if isinstance(db, util.string_types):
            if not spec(config._current):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
        else:
            if not _is_excluded(*db):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
    return decorate 
Example #4
Source File: assertions.py    From android_universal with MIT License 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, *messages):
            return fn(*args, **kw)

    return decorate 
Example #5
Source File: assertions.py    From jbox with MIT License 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, *messages):
            return fn(*args, **kw)

    return decorate 
Example #6
Source File: 027_adjust_harvester.py    From daf-recipes with GNU General Public License v3.0 6 votes vote down vote up
def upgrade(migrate_engine):
    # ignore reflection warnings
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=sa_exc.SAWarning)
        metadata = MetaData()
        metadata.bind = migrate_engine

        harvest_source_table = Table('harvest_source', metadata, autoload=True)
        package_table = Table('package', metadata, autoload=True)

        harvested_document_table = Table('harvested_document', metadata,
            Column('url', UnicodeText, nullable=False),
            Column('guid', UnicodeText, default=u''),
            Column('source_id', UnicodeText, ForeignKey('harvest_source.id')),
            Column('package_id', UnicodeText, ForeignKey('package.id')),
        )

        harvested_document_table.c.url.drop()
        harvested_document_table.c.guid.create(harvested_document_table)
        harvested_document_table.c.source_id.create(harvested_document_table)
        harvested_document_table.c.package_id.create(harvested_document_table) 
Example #7
Source File: tests.py    From pyramid-jsonapi with GNU Affero General Public License v3.0 6 votes vote down vote up
def new_test_app(options=None):
        '''Create a test app.'''
        config_path = '{}/testing.ini'.format(parent_dir)
        if options:
            tmp_cfg = configparser.ConfigParser()
            tmp_cfg.read(config_path)
            tmp_cfg['app:main'].update(options or {})
            config_path = '{}/tmp_testing.ini'.format(parent_dir)
            with open(config_path, 'w') as tmp_file:
                tmp_cfg.write(tmp_file)
        with warnings.catch_warnings():
            # Suppress SAWarning: about Property _jsonapi_id being replaced by
            # Propery _jsonapi_id every time a new app is instantiated.
            warnings.simplefilter(
                "ignore",
                category=SAWarning
            )
            test_app = webtest.TestApp(get_app(config_path))
        if options:
            os.remove(config_path)
        return test_app 
Example #8
Source File: assertions.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def emits_warning_on(db, *warnings):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().
    """
    spec = db_spec(db)

    @decorator
    def decorate(fn, *args, **kw):
        if isinstance(db, util.string_types):
            if not spec(config._current):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
        else:
            if not _is_excluded(*db):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
    return decorate 
Example #9
Source File: assertions.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, assert_=False, *messages):
            return fn(*args, **kw)

    return decorate 
Example #10
Source File: assertions.py    From planespotter with MIT License 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, assert_=False, *messages):
            return fn(*args, **kw)

    return decorate 
Example #11
Source File: assertions.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, assert_=False, *messages):
            return fn(*args, **kw)

    return decorate 
Example #12
Source File: test_clsregistry.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_same_module_same_name(self):
        base = weakref.WeakValueDictionary()
        f1 = MockClass(base, "foo.bar.Foo")
        f2 = MockClass(base, "foo.bar.Foo")
        clsregistry.add_class("Foo", f1)
        gc_collect()

        assert_raises_message(
            exc.SAWarning,
            "This declarative base already contains a class with the "
            "same class name and module name as foo.bar.Foo, and "
            "will be replaced in the string-lookup table.",
            clsregistry.add_class,
            "Foo",
            f2,
        ) 
Example #13
Source File: test_reflection.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_oracle_has_no_on_update_cascade(self):
        bar = Table(
            "bar",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column(
                "foo_id", Integer, ForeignKey("foo.id", onupdate="CASCADE")
            ),
        )
        assert_raises(exc.SAWarning, bar.create)

        bat = Table(
            "bat",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("foo_id", Integer),
            ForeignKeyConstraint(["foo_id"], ["foo.id"], onupdate="CASCADE"),
        )
        assert_raises(exc.SAWarning, bat.create) 
Example #14
Source File: test_reflection.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_unknown_types(self):
        from sqlalchemy.dialects.postgresql import base

        ischema_names = base.PGDialect.ischema_names
        base.PGDialect.ischema_names = {}
        try:
            m2 = MetaData(testing.db)
            assert_raises(exc.SAWarning, Table, "testtable", m2, autoload=True)

            @testing.emits_warning("Did not recognize type")
            def warns():
                m3 = MetaData(testing.db)
                t3 = Table("testtable", m3, autoload=True)
                assert t3.c.answer.type.__class__ == sa.types.NullType

        finally:
            base.PGDialect.ischema_names = ischema_names 
Example #15
Source File: test_versioning.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_notsane_warning(self):
        Foo = self.classes.Foo

        save = testing.db.dialect.supports_sane_rowcount
        testing.db.dialect.supports_sane_rowcount = False
        try:
            s1 = self._fixture()
            f1 = Foo(value="f1")
            f2 = Foo(value="f2")
            s1.add_all((f1, f2))
            s1.commit()

            f1.value = "f1rev2"
            assert_raises(sa.exc.SAWarning, s1.commit)
        finally:
            testing.db.dialect.supports_sane_rowcount = save 
Example #16
Source File: assertions.py    From jbox with MIT License 6 votes vote down vote up
def emits_warning_on(db, *messages):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    """
    @decorator
    def decorate(fn, *args, **kw):
        with expect_warnings_on(db, assert_=False, *messages):
            return fn(*args, **kw)

    return decorate 
Example #17
Source File: test_basic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_invalid_assignment_upwards(self):
        """test that we warn on assign of 'c' to a B, since we will have a
        "C" row that has no joined row, which will cause object
        deleted errors.
        """
        B = self.classes.B

        sess = Session()
        b1 = B()
        b1.class_name = "c"
        sess.add(b1)
        assert_raises_message(
            sa_exc.SAWarning,
            "Flushing object %s with incompatible "
            "polymorphic identity 'c'; the object may not "
            "refresh and/or load correctly" % instance_str(b1),
            sess.flush,
        ) 
Example #18
Source File: test_basic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_entirely_oob_assignment(self):
        """test warn on an unknown polymorphic identity.
        """
        B = self.classes.B

        sess = Session()
        b1 = B()
        b1.class_name = "xyz"
        sess.add(b1)
        assert_raises_message(
            sa_exc.SAWarning,
            "Flushing object %s with incompatible "
            "polymorphic identity 'xyz'; the object may not "
            "refresh and/or load correctly" % instance_str(b1),
            sess.flush,
        ) 
Example #19
Source File: test_basic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_validate_on_upate(self):
        C = self.classes.C

        sess = Session()
        c1 = C()
        sess.add(c1)
        sess.commit()
        sess.expire(c1)

        c1.class_name = "b"
        assert_raises_message(
            sa_exc.SAWarning,
            "Flushing object %s with incompatible "
            "polymorphic identity 'b'; the object may not "
            "refresh and/or load correctly" % instance_str(c1),
            sess.flush,
        ) 
Example #20
Source File: test_basic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_explicit_composite_pk(self):
        person_mapper = mapper(Person, person_table)
        mapper(
            Employee,
            employee_table,
            inherits=person_mapper,
            properties=dict(id=[employee_table.c.eid, person_table.c.id]),
            primary_key=[person_table.c.id, employee_table.c.eid],
        )
        assert_raises_message(
            sa_exc.SAWarning,
            r"On mapper mapped class Employee->employees, "
            "primary key column 'persons.id' is being "
            "combined with distinct primary key column 'employees.eid' "
            "in attribute 'id'. Use explicit properties to give "
            "each column its own mapped attribute name.",
            self._do_test,
            True,
        ) 
Example #21
Source File: test_basic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_pk_fk_different(self):
        class Base(object):
            pass

        class Sub(Base):
            pass

        mapper(Base, base)

        def go():
            mapper(Sub, subtable_two, inherits=Base)

        assert_raises_message(
            sa_exc.SAWarning,
            "Implicitly combining column base.base_id with "
            "column subtable_two.base_id under attribute 'base_id'",
            go,
        ) 
Example #22
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_o2m_only_child_persistent(self):
        User, Address = self.classes.User, self.classes.Address

        self._one_to_many_fixture(o2m=True, m2o=False, o2m_cascade=False)
        sess = Session()
        u1 = User(name="u1")
        a1 = Address(email_address="a1")
        sess.add(a1)
        sess.flush()

        sess.expunge_all()

        u1.addresses.append(a1)
        sess.add(u1)
        assert u1 in sess
        assert a1 not in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #23
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_o2m_backref_child_expunged(self):
        User, Address = self.classes.User, self.classes.Address

        self._one_to_many_fixture(o2m=True, m2o=True, o2m_cascade=False)
        sess = Session()
        u1 = User(name="u1")
        a1 = Address(email_address="a1")
        sess.add(a1)
        sess.flush()

        sess.add(u1)
        u1.addresses.append(a1)
        sess.expunge(a1)
        assert u1 in sess
        assert a1 not in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #24
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_m2o_only_child_expunged(self):
        User, Address = self.classes.User, self.classes.Address

        self._one_to_many_fixture(o2m=False, m2o=True, m2o_cascade=False)
        sess = Session()
        u1 = User(name="u1")
        sess.add(u1)
        sess.flush()

        a1 = Address(email_address="a1")
        a1.user = u1
        sess.add(a1)
        sess.expunge(u1)
        assert u1 not in sess
        assert a1 in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #25
Source File: test_unitofworkv2.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_delete_single_broken_multi_rowcount_still_warns(self):
        Parent, Child = self._fixture()
        sess = Session()
        p1 = Parent(id=1, data=2, child=None)
        sess.add(p1)
        sess.flush()
        sess.flush()

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

        # only one row, so it warns
        with patch.object(
            config.db.dialect, "supports_sane_multi_rowcount", False
        ):
            assert_raises_message(
                exc.SAWarning,
                r"DELETE statement on table 'parent' expected to "
                r"delete 1 row\(s\); 0 were matched.",
                sess.flush,
            ) 
Example #26
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_m2o_backref_child_expunged(self):
        User, Address = self.classes.User, self.classes.Address

        self._one_to_many_fixture(o2m=True, m2o=True, m2o_cascade=False)
        sess = Session()
        u1 = User(name="u1")
        sess.add(u1)
        sess.flush()

        a1 = Address(email_address="a1")
        a1.user = u1
        sess.add(a1)
        sess.expunge(u1)
        assert u1 not in sess
        assert a1 in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #27
Source File: test_unitofworkv2.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_delete_twice(self):
        Parent, Child = self._fixture()
        sess = Session()
        p1 = Parent(id=1, data=2, child=None)
        sess.add(p1)
        sess.commit()

        sess.delete(p1)
        sess.flush()

        sess.delete(p1)

        assert_raises_message(
            exc.SAWarning,
            r"DELETE statement on table 'parent' expected to "
            r"delete 1 row\(s\); 0 were matched.",
            sess.commit,
        ) 
Example #28
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_m2m_only_child_persistent(self):
        Item, Keyword = self.classes.Item, self.classes.Keyword

        self._many_to_many_fixture(fwd=True, bkd=False, fwd_cascade=False)
        sess = Session()
        i1 = Item(description="i1")
        k1 = Keyword(name="k1")
        sess.add(k1)
        sess.flush()

        sess.expunge_all()

        i1.keywords.append(k1)
        sess.add(i1)
        assert i1 in sess
        assert k1 not in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #29
Source File: test_cascade.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_m2m_backref_child_expunged(self):
        Item, Keyword = self.classes.Item, self.classes.Keyword

        self._many_to_many_fixture(fwd=True, bkd=True, fwd_cascade=False)
        sess = Session()
        i1 = Item(description="i1")
        k1 = Keyword(name="k1")
        sess.add(k1)
        sess.flush()

        sess.add(i1)
        i1.keywords.append(k1)
        sess.expunge(k1)
        assert i1 in sess
        assert k1 not in sess
        assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush) 
Example #30
Source File: test_dynamic.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_no_m2o_w_uselist(self):
        users, Address, addresses, User = (
            self.tables.users,
            self.classes.Address,
            self.tables.addresses,
            self.classes.User,
        )
        mapper(
            Address,
            addresses,
            properties={
                "user": relationship(User, uselist=True, lazy="dynamic")
            },
        )
        mapper(User, users)
        assert_raises_message(
            exc.SAWarning,
            "On relationship Address.user, 'dynamic' loaders cannot be "
            "used with many-to-one/one-to-one relationships and/or "
            "uselist=False.",
            configure_mappers,
        )