From 4173a0be5fcf05faea0969fc48f590afbf3313f0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 3 Jul 2022 13:55:20 -0400 Subject: [PATCH] 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 --- test/orm/declarative/test_typed_mapping.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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}) -- 2.47.2