From: Mike Bayer Date: Sun, 3 Jul 2022 17:55:20 +0000 (-0400) Subject: test transfer of default, insert_default X-Git-Tag: rel_2_0_0b1~188^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4173a0be5fcf05faea0969fc48f590afbf3313f0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git test transfer of default, insert_default right now "default" goes to Column.default unconditionally if insert_default is not present, including if dataclasses are in use where the field effectively now does two things. This generally works out because Python side default can be assigned to the object or picked up by Core in any case. However, we might want to look into later on migrating this to have the fields act more separately. I think it's "OK" for now, will try to doc that this might change. Change-Id: I30f2085ec79a6464da4d5c578500848c70d55ec2 --- diff --git a/test/orm/declarative/test_typed_mapping.py b/test/orm/declarative/test_typed_mapping.py index beb5d783bf..4a7b169cd1 100644 --- a/test/orm/declarative/test_typed_mapping.py +++ b/test/orm/declarative/test_typed_mapping.py @@ -87,6 +87,25 @@ class DeclarativeBaseTest(fixtures.TestBase): class MappedColumnTest(fixtures.TestBase, testing.AssertsCompiledSQL): __dialect__ = "default" + @testing.combinations( + "default", "insert_default", argnames="use_paramname" + ) + @testing.combinations(True, False, argnames="use_none") + def test_col_defaults(self, use_paramname, use_none, decl_base): + class Foo(decl_base): + __tablename__ = "foo" + + id: Mapped[int] = mapped_column(primary_key=True) + + data: Mapped[int] = mapped_column( + **{use_paramname: None if use_none else 5} + ) + + if use_none: + assert not Foo.__table__.c.data.default + else: + eq_(Foo.__table__.c.data.default.arg, 5) + def test_legacy_declarative_base(self): typ = VARCHAR(50) Base = declarative_base(type_annotation_map={str: typ})