diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-04-10 12:56:47 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-04-12 15:11:03 -0400 |
commit | 9f43b10e9014e694cb89fe2899dc52f602bf2197 (patch) | |
tree | 03c54cbc80bd98e9d358b6a21a029b8524142696 /test/orm/declarative/test_basic.py | |
parent | 6e5ed192c6435ec107eae524bb2c6959c38bc654 (diff) | |
download | sqlalchemy-9f43b10e9014e694cb89fe2899dc52f602bf2197.tar.gz |
establish column_property and query_expression as readonly from a dc perspective
Fixed bug in ORM Declarative Dataclasses where the
:func:`_orm.queryable_attribute` and :func:`_orm.column_property`
constructs, which are documented as read-only constructs in the context of
a Declarative mapping, could not be used with a
:class:`_orm.MappedAsDataclass` class without adding ``init=False``, which
in the case of :func:`_orm.queryable_attribute` was not possible as no
``init`` parameter was included. These constructs have been modified from a
dataclass perspective to be assumed to be "read only", setting
``init=False`` by default and no longer including them in the pep-681
constructor. The dataclass parameters for :func:`_orm.column_property`
``init``, ``default``, ``default_factory``, ``kw_only`` are now deprecated;
these fields don't apply to :func:`_orm.column_property` as used in a
Declarative dataclasses configuration where the construct would be
read-only. Also added read-specific parameter
:paramref:`_orm.queryable_attribute.compare` to
:func:`_orm.queryable_attribute`; :paramref:`_orm.queryable_attribute.repr`
was already present.
Added missing :paramref:`_orm.mapped_column.active_history` parameter
to :func:`_orm.mapped_column` construct.
Fixes: #9628
Change-Id: I2ab44d6b763b20410bd1ebb5ac949a6d223f1ce2
Diffstat (limited to 'test/orm/declarative/test_basic.py')
-rw-r--r-- | test/orm/declarative/test_basic.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/orm/declarative/test_basic.py b/test/orm/declarative/test_basic.py index 2d712c823..698b66db1 100644 --- a/test/orm/declarative/test_basic.py +++ b/test/orm/declarative/test_basic.py @@ -2593,6 +2593,26 @@ class DeclarativeMultiBaseTest( sess.expunge_all() eq_(sess.query(User).all(), [User(name="u1", a="a", b="b")]) + def test_active_history_columns(self): + class Foo(Base): + __tablename__ = "foo" + + id = Column( + Integer, primary_key=True, test_needs_autoincrement=True + ) + a = column_property(Column(String), active_history=True) + b = mapped_column(String, active_history=True) + c = column_property(Column(String)) + d = mapped_column(String) + + self.assert_compile( + select(Foo), "SELECT foo.id, foo.a, foo.b, foo.c, foo.d FROM foo" + ) + eq_(Foo.a.impl.active_history, True) + eq_(Foo.b.impl.active_history, True) + eq_(Foo.c.impl.active_history, False) + eq_(Foo.d.impl.active_history, False) + def test_column_properties(self): class Address(Base, fixtures.ComparableEntity): |