Here are the examples of the python api sqlalchemy.exc.SAWarning taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
119 Examples
3
Source : util.py
with GNU General Public License v3.0
from Artikash
with GNU General Public License v3.0
from Artikash
def warn(msg, stacklevel=3):
if isinstance(msg, basestring):
warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel)
else:
warnings.warn(msg, stacklevel=stacklevel)
def warn_deprecated(msg, stacklevel=3):
3
Source : assertions.py
with MIT License
from bkerler
with MIT License
from bkerler
def expect_warnings(*messages, **kw):
"""Context manager which expects one or more warnings.
With no arguments, squelches all SAWarnings emitted via
sqlalchemy.util.warn and sqlalchemy.util.warn_limited. Otherwise
pass string expressions that will match selected warnings via regex;
all non-matching warnings are sent through.
The expect version **asserts** that the warnings were in fact seen.
Note that the test suite sets SAWarning warnings to raise exceptions.
"""
return _expect_warnings(sa_exc.SAWarning, messages, **kw)
@contextlib.contextmanager
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bad_freetds_warning(self):
engine = engines.testing_engine()
def _bad_version(connection):
return 95, 10, 255
engine.dialect._get_server_version_info = _bad_version
assert_raises_message(
exc.SAWarning, "Unrecognized server version info", engine.connect
)
class EngineFromConfigTest(fixtures.TestBase):
3
Source : test_reconnect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_cursor_shutdown_in_initialize(self):
db = self._fixture(True, True)
assert_raises_message_context_ok(
exc.SAWarning, "Exception attempting to detect", db.connect
)
eq_(
db.pool.logger.error.mock_calls,
[call("Error closing cursor", exc_info=True)],
)
def _assert_invalidated(fn, *args):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_named_twice(self):
def go():
class Foo(Base):
__tablename__ = "foo"
id = Column(Integer, primary_key=True)
x = Column("x", Integer)
y = Column("x", Integer)
assert_raises_message(
sa.exc.SAWarning,
"On class 'Foo', Column object 'x' named directly multiple times, "
"only one will be used: x, y",
go,
)
def test_column_repeated_under_prop(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_repeated_under_prop(self):
def go():
class Foo(Base):
__tablename__ = "foo"
id = Column(Integer, primary_key=True)
x = Column("x", Integer)
y = column_property(x)
z = Column("x", Integer)
assert_raises_message(
sa.exc.SAWarning,
"On class 'Foo', Column object 'x' named directly multiple times, "
"only one will be used: x, y, z",
go,
)
def test_using_explicit_prop_in_schema_objects(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_duplicate_classes_in_base(self):
class Test(Base):
__tablename__ = "a"
id = Column(Integer, primary_key=True)
assert_raises_message(
sa.exc.SAWarning,
"This declarative base already contains a class with ",
lambda: type(Base)(
"Test",
(Base,),
dict(__tablename__="b", id=Column(Integer, primary_key=True)),
),
)
@testing.teardown_events(MapperEvents)
3
Source : test_clsregistry.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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,
)
def test_resolve(self):
3
Source : test_mixin.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_can_we_access_the_mixin_straight(self):
class Mixin(object):
@declared_attr
def my_prop(cls):
return Column("x", Integer)
assert_raises_message(
sa.exc.SAWarning,
"Unmanaged access of declarative attribute my_prop "
"from non-mapped class Mixin",
getattr,
Mixin,
"my_prop",
)
def test_can_we_access_the_mixin_straight_special_names(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_invalid_assignment_downwards(self):
"""test that we warn on assign of 'b' to a C, since this adds
a row to the C table we'd never load.
"""
C = self.classes.C
sess = Session()
c1 = C()
c1.class_name = "b"
sess.add(c1)
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,
)
def test_invalid_assignment_upwards(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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,
)
def test_not_set_on_upate(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_delete_orphan_without_delete(self):
Address = self.classes.Address
assert_raises_message(
sa_exc.SAWarning,
"The 'delete-orphan' cascade option requires 'delete'.",
relationship,
Address,
cascade="save-update, delete-orphan",
)
def test_bad_cascade(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_o2m_only_child_transient(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")
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)
def test_o2m_only_child_persistent(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_o2m_backref_child_pending(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_o2m_backref_child_transient(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")
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)
def test_o2m_backref_child_transient_nochange(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_o2m_backref_child_expunged_nochange(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_m2o_only_child_transient(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")
a1 = Address(email_address="a1")
a1.user = u1
sess.add(a1)
assert u1 not in sess
assert a1 in sess
assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush)
def test_m2o_only_child_expunged(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_m2o_backref_child_pending(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_m2o_backref_child_transient(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")
a1 = Address(email_address="a1")
a1.user = u1
sess.add(a1)
assert u1 not in sess
assert a1 in sess
assert_raises_message(sa_exc.SAWarning, "not in session", sess.flush)
def test_m2o_backref_child_expunged(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_m2o_backref_child_pending_nochange(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_m2m_only_child_transient(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")
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)
def test_m2m_only_child_persistent(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_m2m_backref_child_pending(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_m2m_backref_child_transient(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")
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)
def test_m2m_backref_child_transient_nochange(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def test_m2m_backref_child_expunged_nochange(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_o2m_commit_warns(self):
User, Address = self.classes.User, self.classes.Address
sess = Session()
u1 = User(name="u1")
sess.add(u1)
a1 = Address(email_address="a1")
a1.user = u1
assert_raises_message(sa_exc.SAWarning, "not in session", sess.commit)
assert a1 not in sess
def test_o2m_flag_on_backref(self):
3
Source : test_cascade.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_m2o_commit_warns(self):
Dingaling, Address = self.classes.Dingaling, self.classes.Address
sess = Session()
a1 = Address(email_address="a1")
d1 = Dingaling()
sess.add(d1)
a1.dingalings.append(d1)
assert a1 not in sess
assert_raises_message(sa_exc.SAWarning, "not in session", sess.commit)
class PendingOrphanTestSingleLevel(fixtures.MappedTest):
3
Source : test_instrumentation.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_del_warning(self):
class A(object):
def __del__(self):
pass
assert_raises_message(
sa.exc.SAWarning,
r"__del__\(\) method on class "
r" < class '.*\.A'> will cause "
r"unreachable cycles and memory leaks, as SQLAlchemy "
r"instrumentation often creates reference cycles. "
r"Please remove this method.",
mapper,
A,
self.fixture(),
)
class OnLoadTest(fixtures.ORMTest):
3
Source : test_joins.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_raises_on_dupe_target_rel(self):
User = self.classes.User
assert_raises_message(
sa.exc.SAWarning,
"Pathed join target Order.items has already been joined to; "
"skipping",
lambda: create_session()
.query(User)
.outerjoin("orders", "items")
.outerjoin("orders", "items"),
)
def test_from_joinpoint(self):
3
Source : test_query.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_get_fully_null_pk(self):
User = self.classes.User
s = Session()
q = s.query(User)
assert_raises_message(
sa_exc.SAWarning,
r"fully NULL primary key identity cannot load any object. "
"This condition may raise an error in a future release.",
q.get,
None,
)
def test_get_fully_null_composite_pk(self, outerjoin_mapping):
3
Source : test_query.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_get_fully_null_composite_pk(self, outerjoin_mapping):
UserThing = outerjoin_mapping
s = Session()
q = s.query(UserThing)
assert_raises_message(
sa_exc.SAWarning,
r"fully NULL primary key identity cannot load any object. "
"This condition may raise an error in a future release.",
q.get,
(None, None),
)
def test_no_criterion(self):
3
Source : test_relationships.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_warn_one(self):
assert_raises_message(
exc.SAWarning,
r"relationship '(?:BSub1.a|BSub2.a_member|B.a)' will copy column "
r"(?:a.id|a_member.a_id) to column b.a_id",
self._fixture_one,
add_b_a=True,
add_bsub1_a=True,
)
@testing.provide_metadata
3
Source : test_relationships.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_warn_two(self):
assert_raises_message(
exc.SAWarning,
r"relationship '(?:BSub1.a|B.a_member)' will copy column "
r"(?:a.id|a_member.a_id) to column b.a_id",
self._fixture_one,
add_b_amember=True,
add_bsub1_a=True,
)
@testing.provide_metadata
3
Source : test_relationships.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_warn_three(self):
assert_raises_message(
exc.SAWarning,
r"relationship '(?:BSub1.a|B.a_member|B.a)' will copy column "
r"(?:a.id|a_member.a_id) to column b.a_id",
self._fixture_one,
add_b_amember=True,
add_bsub1_a=True,
add_b_a=True,
)
@testing.provide_metadata
3
Source : test_rel_fn.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _assert_non_simple_warning(self, fn):
assert_raises_message(
exc.SAWarning,
"Non-simple column elements in "
"primary join condition for property "
r"None - consider using remote\(\) "
"annotations to mark the remote side.",
fn,
)
def _assert_raises_no_relevant_fks(
3
Source : test_session.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_extra_dirty_state_post_flush_warning(self):
s, a1, a2 = self._test_extra_dirty_state()
assert_raises_message(
sa.exc.SAWarning,
"Attribute history events accumulated on 1 previously "
"clean instances",
s.commit,
)
def test_extra_dirty_state_post_flush_state(self):
3
Source : test_session.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _test(self, fn, method):
User = self.classes.User
Address = self.classes.Address
s = Session()
event.listen(User, "after_insert", fn)
u1 = User(name="u1", addresses=[Address(name="a1")])
s.add(u1)
assert_raises_message(
sa.exc.SAWarning, "Usage of the '%s'" % method, s.commit
)
3
Source : test_versioning.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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
def test_basic(self):
3
Source : test_defaults.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_nonunicode_default(self):
default = b("foo")
assert_raises_message(
sa.exc.SAWarning,
"Unicode column 'foobar' has non-unicode "
"default value b?'foo' specified.",
Column,
"foobar",
Unicode(32),
default=default,
)
class InsertFromSelectTest(fixtures.TablesTest):
3
Source : test_metadata.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pk_col_mismatch_one(self):
m = MetaData()
assert_raises_message(
exc.SAWarning,
"Table 't' specifies columns 'x' as primary_key=True, "
"not matching locally specified columns 'q'",
Table,
"t",
m,
Column("x", Integer, primary_key=True),
Column("q", Integer),
PrimaryKeyConstraint("q"),
)
def test_pk_col_mismatch_two(self):
3
Source : test_metadata.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pk_col_mismatch_two(self):
m = MetaData()
assert_raises_message(
exc.SAWarning,
"Table 't' specifies columns 'a', 'b', 'c' as primary_key=True, "
"not matching locally specified columns 'b', 'c'",
Table,
"t",
m,
Column("a", Integer, primary_key=True),
Column("b", Integer, primary_key=True),
Column("c", Integer, primary_key=True),
PrimaryKeyConstraint("b", "c"),
)
@testing.emits_warning("Table 't'")
3
Source : test_selectable.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _assert_labels_warning(self, s):
assert_raises_message(
exc.SAWarning,
r"replaced by Column.*, which has the same key",
lambda: s.c,
)
def _assert_result_keys(self, s, keys):
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_unicode_warnings_typelevel_native_unicode(self):
unicodedata = self.data
u = Unicode()
dialect = default.DefaultDialect()
dialect.supports_unicode_binds = True
uni = u.dialect_impl(dialect).bind_processor(dialect)
if util.py3k:
assert_raises(exc.SAWarning, uni, b"x")
assert isinstance(uni(unicodedata), str)
else:
assert_raises(exc.SAWarning, uni, "x")
assert isinstance(uni(unicodedata), unicode) # noqa
def test_unicode_warnings_typelevel_sqla_unicode(self):
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_unicode_warnings_typelevel_sqla_unicode(self):
unicodedata = self.data
u = Unicode()
dialect = default.DefaultDialect()
dialect.supports_unicode_binds = False
uni = u.dialect_impl(dialect).bind_processor(dialect)
assert_raises(exc.SAWarning, uni, util.b("x"))
assert isinstance(uni(unicodedata), util.binary_type)
eq_(uni(unicodedata), unicodedata.encode("utf-8"))
def test_unicode_warnings_totally_wrong_type(self):
3
Source : test_engine.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_bad_freetds_warning(self):
engine = engines.testing_engine()
def _bad_version(connection):
return 95, 10, 255
engine.dialect._get_server_version_info = _bad_version
assert_raises_message(
exc.SAWarning, "Unrecognized server version info", engine.connect
)
class FastExecutemanyTest(fixtures.TestBase):
3
Source : test_reconnect.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_cursor_shutdown_in_initialize(self):
db = self._fixture(True, True)
assert_warns_message(
exc.SAWarning, "Exception attempting to detect", db.connect
)
eq_(
db.pool.logger.error.mock_calls,
[call("Error closing cursor", exc_info=True)],
)
def _assert_invalidated(fn, *args):
3
Source : test_basic.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_invalid_assignment_downwards(self):
"""test that we warn on assign of 'b' to a C, since this adds
a row to the C table we'd never load.
"""
C = self.classes.C
sess = fixture_session()
c1 = C()
c1.class_name = "b"
sess.add(c1)
assert_warns_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,
)
def test_invalid_assignment_upwards(self):
3
Source : test_basic.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_entirely_oob_assignment(self):
"""test warn on an unknown polymorphic identity."""
B = self.classes.B
sess = fixture_session()
b1 = B()
b1.class_name = "xyz"
sess.add(b1)
assert_warns_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,
)
def test_not_set_on_upate(self):
3
Source : test_cascade.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_delete_orphan_without_delete(self):
Address = self.classes.Address
assert_warns_message(
sa_exc.SAWarning,
"The 'delete-orphan' cascade option requires 'delete'.",
relationship,
Address,
cascade="save-update, delete-orphan",
)
def test_bad_cascade(self):
3
Source : test_cascade.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_o2m_only_child_transient(self):
User, Address = self.classes.User, self.classes.Address
self._one_to_many_fixture(o2m=True, m2o=False, o2m_cascade=False)
sess = fixture_session()
u1 = User(name="u1")
a1 = Address(email_address="a1")
u1.addresses.append(a1)
sess.add(u1)
assert u1 in sess
assert a1 not in sess
assert_warns_message(sa_exc.SAWarning, "not in session", sess.flush)
def test_o2m_only_child_persistent(self):
3
Source : test_cascade.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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 = fixture_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_warns_message(sa_exc.SAWarning, "not in session", sess.flush)
def test_o2m_backref_child_pending(self):
See More Examples