--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 9550
+
+ Fixed issue where the :func:`_orm.mapped_column` construct would raise an
+ internal error if used on a Declarative mixin and included the
+ :paramref:`_orm.mapped_column.deferred` parameter.
new = self.__class__.__new__(self.__class__)
new.column = self.column._copy(**kw)
new.deferred = self.deferred
+ new.deferred_group = self.deferred_group
+ new.deferred_raiseload = self.deferred_raiseload
new.foreign_keys = new.column.foreign_keys
new._has_nullable = self._has_nullable
new._attribute_options = self._attribute_options
from typing import Optional
from typing import Set
from typing import Type
+from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union
import uuid
is_(User.__table__.c.data.type.__class__, Integer)
@testing.combinations(True, False, argnames="include_rhs_type")
+ @testing.combinations(True, False, argnames="use_mixin")
def test_construct_nullability_overrides(
- self, decl_base, include_rhs_type
+ self, decl_base, include_rhs_type, use_mixin
):
if include_rhs_type:
}
)
- class User(decl_base):
- __tablename__ = "users"
+ if TYPE_CHECKING:
- id: Mapped[int] = mapped_column(primary_key=True)
+ class user_base:
+ pass
+
+ else:
+ if use_mixin:
+ user_base = object
+ else:
+ user_base = decl_base
+
+ class UserPossibleMixin(user_base):
+ if not use_mixin:
+ __tablename__ = "users"
+
+ id: Mapped[int] = mapped_column(primary_key=True) # noqa: A001
lnnl_rndf: Mapped[str] = mapped_column(*args)
lnnl_rnnl: Mapped[str] = mapped_column(*args, nullable=False)
# test #9177 cases
anno_1a: Mapped[anno_str] = mapped_column(*args)
anno_1b: Mapped[anno_str] = mapped_column(*args, nullable=True)
+ anno_1c: Mapped[anno_str] = mapped_column(*args, deferred=True)
+ anno_1d: Mapped[anno_str] = mapped_column(
+ *args, deferred=True, deferred_group="mygroup"
+ )
anno_2a: Mapped[anno_str_optional] = mapped_column(*args)
anno_2b: Mapped[anno_str_optional] = mapped_column(
*args, nullable=True
)
+ if use_mixin:
+
+ class User(UserPossibleMixin, decl_base):
+ __tablename__ = "users"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+
+ else:
+ User = UserPossibleMixin
+
+ eq_(User.anno_1b.property.deferred, False)
+ eq_(User.anno_1c.property.deferred, True)
+ eq_(User.anno_1d.property.group, "mygroup")
+
is_false(User.__table__.c.lnnl_rndf.nullable)
is_false(User.__table__.c.lnnl_rnnl.nullable)
is_true(User.__table__.c.lnnl_rnl.nullable)
from typing import Optional
from typing import Set
from typing import Type
+from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union
import uuid
is_(User.__table__.c.data.type.__class__, Integer)
@testing.combinations(True, False, argnames="include_rhs_type")
+ @testing.combinations(True, False, argnames="use_mixin")
def test_construct_nullability_overrides(
- self, decl_base, include_rhs_type
+ self, decl_base, include_rhs_type, use_mixin
):
if include_rhs_type:
}
)
- class User(decl_base):
- __tablename__ = "users"
+ if TYPE_CHECKING:
- id: Mapped[int] = mapped_column(primary_key=True)
+ class user_base:
+ pass
+
+ else:
+ if use_mixin:
+ user_base = object
+ else:
+ user_base = decl_base
+
+ class UserPossibleMixin(user_base):
+ if not use_mixin:
+ __tablename__ = "users"
+
+ id: Mapped[int] = mapped_column(primary_key=True) # noqa: A001
lnnl_rndf: Mapped[str] = mapped_column(*args)
lnnl_rnnl: Mapped[str] = mapped_column(*args, nullable=False)
# test #9177 cases
anno_1a: Mapped[anno_str] = mapped_column(*args)
anno_1b: Mapped[anno_str] = mapped_column(*args, nullable=True)
+ anno_1c: Mapped[anno_str] = mapped_column(*args, deferred=True)
+ anno_1d: Mapped[anno_str] = mapped_column(
+ *args, deferred=True, deferred_group="mygroup"
+ )
anno_2a: Mapped[anno_str_optional] = mapped_column(*args)
anno_2b: Mapped[anno_str_optional] = mapped_column(
*args, nullable=True
)
+ if use_mixin:
+
+ class User(UserPossibleMixin, decl_base):
+ __tablename__ = "users"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+
+ else:
+ User = UserPossibleMixin
+
+ eq_(User.anno_1b.property.deferred, False)
+ eq_(User.anno_1c.property.deferred, True)
+ eq_(User.anno_1d.property.group, "mygroup")
+
is_false(User.__table__.c.lnnl_rndf.nullable)
is_false(User.__table__.c.lnnl_rnnl.nullable)
is_true(User.__table__.c.lnnl_rnl.nullable)