:tickets: 8777
Fixed a suite of issues involving :class:`.Mapped` use with dictionary
- types, such as ``Mapped[dict[str, str] | None]``, would not be correctly
+ types, such as ``Mapped[Dict[str, str] | None]``, would not be correctly
interpreted in Declarative ORM mappings. Support to correctly
"de-optionalize" this type including for lookup in ``type_annotation_map``
has been fixed.
id: int = Column(Integer, primary_key=True)
# will raise
- bars: list["Bar"] = relationship("Bar", back_populates="foo")
+ bars: List["Bar"] = relationship("Bar", back_populates="foo")
class Bar(Base):
id: int = Column(Integer, primary_key=True)
- bars: list["Bar"] = relationship("Bar", back_populates="foo")
+ bars: List["Bar"] = relationship("Bar", back_populates="foo")
class Bar(Base):
The setup for each of the following sections is as follows::
from __future__ import annotations
+ from typing import List
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship(back_populates="parent")
+ children: Mapped[List["Child"]] = relationship(back_populates="parent")
class Child(Base):
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship()
+ children: Mapped[List["Child"]] = relationship()
class Child(Base):
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship(back_populates="parent")
+ children: Mapped[List["Child"]] = relationship(back_populates="parent")
class Child(Base):
:func:`_orm.relationship` is derived from the collection type passed to the
:class:`_orm.Mapped` container type. The example from the previous section
may be written to use a ``set`` rather than a ``list`` for the
-``Parent.children`` collection using ``Mapped[set["Child"]]``::
+``Parent.children`` collection using ``Mapped[Set["Child"]]``::
class Parent(Base):
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[set["Child"]] = relationship(back_populates="parent")
+ children: Mapped[Set["Child"]] = relationship(back_populates="parent")
When using non-annotated forms including imperative mappings, the Python
class to use as a collection may be passed using the
__tablename__ = "child_table"
id: Mapped[int] = mapped_column(primary_key=True)
- parents: Mapped[list["Parent"]] = relationship(back_populates="child")
+ parents: Mapped[List["Parent"]] = relationship(back_populates="child")
.. _relationship_patterns_nullable_m2o:
__tablename__ = "child_table"
id: Mapped[int] = mapped_column(primary_key=True)
- parents: Mapped[list["Parent"]] = relationship(back_populates="child")
+ parents: Mapped[List["Parent"]] = relationship(back_populates="child")
Above, the column for ``Parent.child_id`` will be created in DDL to allow
``NULL`` values. When using :func:`_orm.mapped_column` with explicit typing
__tablename__ = "child_table"
id: Mapped[int] = mapped_column(primary_key=True)
- parents: Mapped[list[Parent]] = relationship(back_populates="child")
+ parents: Mapped[List[Parent]] = relationship(back_populates="child")
.. _relationships_one_to_one:
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list[Child]] = relationship(secondary=association_table)
+ children: Mapped[List[Child]] = relationship(secondary=association_table)
class Child(Base):
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list[Child]] = relationship(
+ children: Mapped[List[Child]] = relationship(
secondary=association_table, back_populates="parents"
)
__tablename__ = "right_table"
id: Mapped[int] = mapped_column(primary_key=True)
- parents: Mapped[list[Parent]] = relationship(
+ parents: Mapped[List[Parent]] = relationship(
secondary=association_table, back_populates="children"
)
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[set["Child"]] = relationship(secondary=association_table)
+ children: Mapped[Set["Child"]] = relationship(secondary=association_table)
When using non-annotated forms including imperative mappings, as is
the case with one-to-many, the Python
class Parent(Base):
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Association"]] = relationship()
+ children: Mapped[List["Association"]] = relationship()
class Child(Base):
class Parent(Base):
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Association"]] = relationship(back_populates="parent")
+ children: Mapped[List["Association"]] = relationship(back_populates="parent")
class Child(Base):
__tablename__ = "right_table"
id: Mapped[int] = mapped_column(primary_key=True)
- parents: Mapped[list["Association"]] = relationship(back_populates="child")
+ parents: Mapped[List["Association"]] = relationship(back_populates="child")
Working with the association pattern in its direct form requires that child
objects are associated with an association instance before being appended to
id: Mapped[int] = mapped_column(primary_key=True)
# many-to-many relationship to Child, bypassing the `Association` class
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
secondary="association_table", back_populates="parents"
)
# association between Parent -> Association -> Child
- child_associations: Mapped[list["Association"]] = relationship(
+ child_associations: Mapped[List["Association"]] = relationship(
back_populates="parent"
)
id: Mapped[int] = mapped_column(primary_key=True)
# many-to-many relationship to Parent, bypassing the `Association` class
- parents: Mapped[list["Parent"]] = relationship(
+ parents: Mapped[List["Parent"]] = relationship(
secondary="association_table", back_populates="children"
)
# association between Child -> Association -> Parent
- parent_associations: Mapped[list["Association"]] = relationship(
+ parent_associations: Mapped[List["Association"]] = relationship(
back_populates="child"
)
id: Mapped[int] = mapped_column(primary_key=True)
# many-to-many relationship to Child, bypassing the `Association` class
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
secondary="association_table", back_populates="parents", viewonly=True
)
# association between Parent -> Association -> Child
- child_associations: Mapped[list["Association"]] = relationship(
+ child_associations: Mapped[List["Association"]] = relationship(
back_populates="parent"
)
id: Mapped[int] = mapped_column(primary_key=True)
# many-to-many relationship to Parent, bypassing the `Association` class
- parents: Mapped[list["Parent"]] = relationship(
+ parents: Mapped[List["Parent"]] = relationship(
secondary="association_table", back_populates="children", viewonly=True
)
# association between Child -> Association -> Parent
- parent_associations: Mapped[list["Association"]] = relationship(
+ parent_associations: Mapped[List["Association"]] = relationship(
back_populates="child"
)
class Parent(Base):
# ...
- children: Mapped[list["Child"]] = relationship(back_populates="parent")
+ children: Mapped[List["Child"]] = relationship(back_populates="parent")
class Child(Base):
class Parent(Base):
# ...
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
order_by="desc(Child.email_address)",
primaryjoin="Parent.id == Child.parent_id",
)
class Parent(Base):
# ...
- children: Mapped[list["myapp.mymodel.Child"]] = relationship(
+ children: Mapped[List["myapp.mymodel.Child"]] = relationship(
order_by="desc(myapp.mymodel.Child.email_address)",
primaryjoin="myapp.mymodel.Parent.id == myapp.mymodel.Child.parent_id",
)
class Parent(Base):
# ...
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
"myapp.mymodel.Child",
order_by="desc(myapp.mymodel.Child.email_address)",
primaryjoin="myapp.mymodel.Parent.id == myapp.mymodel.Child.parent_id",
class Parent(Base):
# ...
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
"model1.Child",
order_by="desc(mymodel1.Child.email_address)",
primaryjoin="Parent.id == model1.Child.parent_id",
class Parent(Base):
# ...
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
_resolve_child_model(),
order_by=lambda: desc(_resolve_child_model().email_address),
primaryjoin=lambda: Parent.id == _resolve_child_model().parent_id,
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship(
+ children: Mapped[List["Child"]] = relationship(
"Child", secondary=lambda: association_table
)
__tablename__ = "left_table"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship(secondary="association_table")
+ children: Mapped[List["Child"]] = relationship(secondary="association_table")
.. warning:: When passed as a string,
:paramref:`_orm.relationship.secondary` argument is interpreted using Python's
parent_id: Mapped[int] = mapped_column(primary_key=True)
# use a list
- children: Mapped[list["Child"]] = relationship()
+ children: Mapped[List["Child"]] = relationship()
class Child(Base):
Or for a ``set``, illustrated in the same
``Parent.children`` collection::
+ from typing import Set
from sqlalchemy import ForeignKey
from sqlalchemy.orm import DeclarativeBase
parent_id: Mapped[int] = mapped_column(primary_key=True)
# use a set
- children: Mapped[set["Child"]] = relationship()
+ children: Mapped[Set["Child"]] = relationship()
class Child(Base):
is required in this case so that the :func:`.attribute_keyed_dict`
may be appropriately parametrized::
+ from typing import Dict
from typing import Optional
from sqlalchemy import ForeignKey
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=attribute_keyed_dict("keyword"),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=attribute_keyed_dict("note_key"),
back_populates="item",
cascade="all, delete-orphan",
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=column_keyed_dict(Note.__table__.c.keyword),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=mapped_collection(lambda note: note.text[0:10]),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- bs: Mapped[dict[str, "B"]] = relationship(
+ bs: Mapped[Dict[str, "B"]] = relationship(
collection_class=attribute_keyed_dict("data"),
back_populates="a",
)
nickname: Mapped[Optional[str]] = mapped_column(String(64))
create_date: Mapped[datetime] = mapped_column(insert_default=func.now())
- addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+ addresses: Mapped[List["Address"]] = relationship(back_populates="user")
class Address(Base):
decorator rather than using the :class:`_orm.DeclarativeBase` superclass::
from datetime import datetime
+ from typing import List
from typing import Optional
from sqlalchemy import ForeignKey
nickname: Mapped[Optional[str]] = mapped_column(String(64))
create_date: Mapped[datetime] = mapped_column(insert_default=func.now())
- addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+ addresses: Mapped[List["Address"]] = relationship(back_populates="user")
@mapper_registry.mapped
__tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(64))
- kw: Mapped[list[Keyword]] = relationship(secondary=lambda: user_keyword_table)
+ kw: Mapped[List[Keyword]] = relationship(secondary=lambda: user_keyword_table)
def __init__(self, name: str):
self.name = name
# proxy the 'keyword' attribute from the 'kw' relationship
- keywords: AssociationProxy[list[str]] = association_proxy("kw", "keyword")
+ keywords: AssociationProxy[List[str]] = association_proxy("kw", "keyword")
class Keyword(Base):
...
# use Keyword(keyword=kw) on append() events
- keywords: AssociationProxy[list[str]] = association_proxy(
+ keywords: AssociationProxy[List[str]] = association_proxy(
"kw", "keyword", creator=lambda kw: Keyword(keyword=kw)
)
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(64))
- user_keyword_associations: Mapped[list[UserKeywordAssociation]] = relationship(
+ user_keyword_associations: Mapped[List[UserKeywordAssociation]] = relationship(
back_populates="user",
cascade="all, delete-orphan",
)
# association proxy of "user_keyword_associations" collection
# to "keyword" attribute
- keywords: AssociationProxy[list[Keyword]] = association_proxy(
+ keywords: AssociationProxy[List[Keyword]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda keyword: UserKeywordAssociation(keyword=Keyword(keyword)),
when new elements are added to the dictionary::
from __future__ import annotations
+ from typing import Dict
from sqlalchemy import ForeignKey
from sqlalchemy import String
# user/user_keyword_associations relationship, mapping
# user_keyword_associations with a dictionary against "special_key" as key.
- user_keyword_associations: Mapped[dict[str, UserKeywordAssociation]] = relationship(
+ user_keyword_associations: Mapped[Dict[str, UserKeywordAssociation]] = relationship(
back_populates="user",
collection_class=attribute_keyed_dict("special_key"),
cascade="all, delete-orphan",
# proxy to 'user_keyword_associations', instantiating
# UserKeywordAssociation assigning the new key to 'special_key',
# values to 'keyword'.
- keywords: AssociationProxy[dict[str, Keyword]] = association_proxy(
+ keywords: AssociationProxy[Dict[str, Keyword]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda k, v: UserKeywordAssociation(special_key=k, keyword=v),
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(64))
- user_keyword_associations: Mapped[dict[str, UserKeywordAssociation]] = relationship(
+ user_keyword_associations: Mapped[Dict[str, UserKeywordAssociation]] = relationship(
back_populates="user",
collection_class=attribute_keyed_dict("special_key"),
cascade="all, delete-orphan",
)
# the same 'user_keyword_associations'->'keyword' proxy as in
# the basic dictionary example.
- keywords: AssociationProxy[dict[str, str]] = association_proxy(
+ keywords: AssociationProxy[Dict[str, str]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda k, v: UserKeywordAssociation(special_key=k, keyword=v),
# 'keyword' is changed to be a proxy to the
# 'keyword' attribute of 'Keyword'
- keyword: AssociationProxy[dict[str, str]] = association_proxy("kw", "keyword")
+ keyword: AssociationProxy[Dict[str, str]] = association_proxy("kw", "keyword")
class Keyword(Base):
)
# column-targeted association proxy
- special_keys: AssociationProxy[list[str]] = association_proxy(
+ special_keys: AssociationProxy[List[str]] = association_proxy(
"user_keyword_associations", "special_key"
)
import asyncio
import datetime
+ from typing import List
from sqlalchemy import ForeignKey
from sqlalchemy import func
id: Mapped[int] = mapped_column(primary_key=True)
data: Mapped[str]
create_date: Mapped[datetime.datetime] = mapped_column(server_default=func.now())
- bs: Mapped[list[B]] = relationship()
+ bs: Mapped[List[B]] = relationship()
class B(Base):
__tablename__ = "company"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
- employees: Mapped[list[Employee]] = relationship(back_populates="company")
+ employees: Mapped[List[Employee]] = relationship(back_populates="company")
class Employee(Base):
__tablename__ = "company"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
- managers: Mapped[list[Manager]] = relationship(back_populates="company")
+ managers: Mapped[List[Manager]] = relationship(back_populates="company")
class Employee(Base):
__tablename__ = "company"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
- employees: Mapped[list[Employee]] = relationship(back_populates="company")
+ employees: Mapped[List[Employee]] = relationship(back_populates="company")
class Employee(Base):
__tablename__ = "company"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
- managers: Mapped[list[Manager]] = relationship(back_populates="company")
+ managers: Mapped[List[Manager]] = relationship(back_populates="company")
class Employee(Base):
# ...
- children: Mapped[list[MyRelatedClass]] = relationship(lazy="raise")
+ children: Mapped[List[MyRelatedClass]] = relationship(lazy="raise")
Above, attribute access on the ``children`` collection will raise an exception
if it was not previously populated. This includes read access but for
.. sourcecode:: python
+ >>> from typing import List
>>> from sqlalchemy import create_engine
>>> from sqlalchemy import ForeignKey
>>> from sqlalchemy.orm import DeclarativeBase
... __tablename__ = "company"
... id: Mapped[int] = mapped_column(primary_key=True)
... name: Mapped[str]
- ... employees: Mapped[list["Employee"]] = relationship(back_populates="company")
+ ... employees: Mapped[List["Employee"]] = relationship(back_populates="company")
>>>
>>> class Employee(Base):
... __tablename__ = "employee"
... __tablename__ = "manager"
... id: Mapped[int] = mapped_column(ForeignKey("employee.id"), primary_key=True)
... manager_name: Mapped[str]
- ... paperwork: Mapped[list["Paperwork"]] = relationship()
+ ... paperwork: Mapped[List["Paperwork"]] = relationship()
... __mapper_args__ = {
... "polymorphic_identity": "manager",
... }
relationship to use :ref:`selectin_eager_loading` when a SELECT
statement for ``Parent`` objects is emitted::
+ from typing import List
+
from sqlalchemy import ForeignKey
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
__tablename__ = "parent"
id: Mapped[int] = mapped_column(primary_key=True)
- children: Mapped[list["Child"]] = relationship(lazy="selectin")
+ children: Mapped[List["Child"]] = relationship(lazy="selectin")
class Child(Base):
Python object model, as well as :term:`database metadata` that describes
real SQL tables that exist, or will exist, in a particular database::
+ >>> from typing import List
>>> from typing import Optional
>>> from sqlalchemy import ForeignKey
>>> from sqlalchemy import String
... name: Mapped[str] = mapped_column(String(30))
... fullname: Mapped[Optional[str]]
...
- ... addresses: Mapped[list["Address"]] = relationship(
+ ... addresses: Mapped[List["Address"]] = relationship(
... back_populates="user", cascade="all, delete-orphan"
... )
...
# ... mapped_column() mappings
- addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+ addresses: Mapped[List["Address"]] = relationship(back_populates="user")
class Address(Base):
class User(Base):
__tablename__ = "user_account"
- addresses: Mapped[list["Address"]] = relationship(
+ addresses: Mapped[List["Address"]] = relationship(
back_populates="user", lazy="selectin"
)
>>> class User(Base):
... __tablename__ = "user_account"
... id: Mapped[int] = mapped_column(primary_key=True)
- ... addresses: Mapped[list["Address"]] = relationship(
+ ... addresses: Mapped[List["Address"]] = relationship(
... back_populates="user", lazy="raise_on_sql"
... )
from typing import Any
from typing import List
from typing import Optional
+from typing import Tuple
from . import array as _array
from . import hstore as _hstore
else:
return False, {}
- def _kind_to_relkinds(self, kind: ObjectKind) -> tuple[str, ...]:
+ def _kind_to_relkinds(self, kind: ObjectKind) -> Tuple[str, ...]:
if kind is ObjectKind.ANY:
return pg_catalog.RELKINDS_ALL_TABLE_LIKE
relkinds = ()
from typing import Iterable
from typing import Iterator
from typing import KeysView
+from typing import List
from typing import Mapping
from typing import MutableMapping
from typing import MutableSequence
def __ne__(self, other: object) -> bool:
return list(self) != other
- def __lt__(self, other: list[_T]) -> bool:
+ def __lt__(self, other: List[_T]) -> bool:
return list(self) < other
- def __le__(self, other: list[_T]) -> bool:
+ def __le__(self, other: List[_T]) -> bool:
return list(self) <= other
- def __gt__(self, other: list[_T]) -> bool:
+ def __gt__(self, other: List[_T]) -> bool:
return list(self) > other
- def __ge__(self, other: list[_T]) -> bool:
+ def __ge__(self, other: List[_T]) -> bool:
return list(self) >= other
- def __add__(self, other: list[_T]) -> list[_T]:
+ def __add__(self, other: List[_T]) -> List[_T]:
try:
other = list(other)
except TypeError:
return NotImplemented
return list(self) + other
- def __radd__(self, other: list[_T]) -> list[_T]:
+ def __radd__(self, other: List[_T]) -> List[_T]:
try:
other = list(other)
except TypeError:
return NotImplemented
return other + list(self)
- def __mul__(self, n: SupportsIndex) -> list[_T]:
+ def __mul__(self, n: SupportsIndex) -> List[_T]:
if not isinstance(n, int):
return NotImplemented
return list(self) * n
- def __rmul__(self, n: SupportsIndex) -> list[_T]:
+ def __rmul__(self, n: SupportsIndex) -> List[_T]:
if not isinstance(n, int):
return NotImplemented
return n * list(self)
ls = list(self)
return ls.index(value, *arg)
- def copy(self) -> list[_T]:
+ def copy(self) -> List[_T]:
return list(self)
def __repr__(self) -> str:
for key in removals:
del self[key]
- def copy(self) -> dict[_KT, _VT]:
+ def copy(self) -> Dict[_KT, _VT]:
return dict(self.items())
def __hash__(self) -> NoReturn:
from typing import NoReturn
from typing import Optional
from typing import overload
+from typing import Tuple
from typing import Type
from typing import TypeVar
import weakref
def __init__(
self,
func: Callable[..., AsyncIterator[_T_co]],
- args: tuple[Any, ...],
- kwds: dict[str, Any],
+ args: Tuple[Any, ...],
+ kwds: Dict[str, Any],
):
self.gen = func(*args, **kwds) # type: ignore
)
}
- many_to_many: list[
- tuple[
- Table,
- Table,
- list[ForeignKeyConstraint],
- Table,
- ]
- ] = []
+ many_to_many: List[
+ Tuple[Table, Table, List[ForeignKeyConstraint], Table]
+ ]
+ many_to_many = []
bookkeeping = cls._sa_automapbase_bookkeeping
metadata_tables = cls.metadata.tables
if len(fk_constraints) != 2:
return None, None, None
- cols: list[Column[Any]] = sum(
+ cols: List[Column[Any]] = sum(
[
[fk.parent for fk in fk_constraint.elements]
for fk_constraint in fk_constraints
automap_base, referred_cls, local_cls, constraint
)
- o2m_kws: dict[str, Union[str, bool]] = {}
+ o2m_kws: Dict[str, Union[str, bool]] = {}
nullable = False not in {fk.parent.nullable for fk in fks}
if not nullable:
o2m_kws["cascade"] = "all, delete-orphan"
else:
return value
- def __getstate__(self) -> dict[_KT, _VT]:
+ def __getstate__(self) -> Dict[_KT, _VT]:
return dict(self)
def __setstate__(
else:
return value
- def __getstate__(self) -> set[_T]:
+ def __getstate__(self) -> Set[_T]:
return set(self)
def __setstate__(self, state: Iterable[_T]) -> None:
type: Mapped[str] = mapped_column(String(50))
@declared_attr.directive
- def __mapper_args__(cls) -> dict[str, Any]:
+ def __mapper_args__(cls) -> Dict[str, Any]:
if cls.__name__ == 'Employee':
return {
"polymorphic_on":cls.type,