There is a bunch of brittle class logic happening in
AbstractConcreteBase that makes this more rigid when you add a class
into the hierarchy, but since your FooBase already has two classes,
you can just add one more which does not get in ABC's way:
Base = declarative_base()
class DontCastNull(object):
@classmethod
def _create_polymorphic_union(cls, mappers):
return polymorphic_union(OrderedDict(
(mp.polymorphic_identity, mp.local_table)
for mp in mappers
), 'type', 'pjoin', cast_nulls=False)
class Employee(DontCastNull, AbstractConcreteBase, Base):
pass
or put the method on your mapped class:
class Employee(AbstractConcreteBase, Base):
@classmethod
def _create_polymorphic_union(cls, mappers):
return polymorphic_union(OrderedDict(
(mp.polymorphic_identity, mp.local_table)
for mp in mappers
), 'type', 'pjoin', cast_nulls=False)
clearly we should make it easier for AbstractConcreteBase to pass in
the cast_nulls flag as well as anything else but it likely still
involve a class-level flag on the basemost mapped class or a mixin.
Getting AbstractConcreteBase to accept __abstract__ classes below it
should be fixed too but that's more complicated to make it work.
>
> Base = declarative_base()
>
> class AbstractConcreteBase_ORA(AbstractConcreteBase):
> # override polymorphic union because of Oracle
> @classmethod
> def _create_polymorphic_union(cls, mappers):
> return polymorphic_union(OrderedDict(
> (mp.polymorphic_identity, mp.local_table)
> for mp in mappers
> ), 'type', 'pjoin', False)
>
> class FooBase(AbstractConcreteBase_ORA, Base):
> common = Column(Integer, primary_key=True)
>
> class Foo(FooBase, Base):
>
> noncommon = Column(Text)
>
> __mapper_args__ = {
> 'polymorphic_identity': 'foo',
> 'concrete': True
> }
>
>
> class Bar(FooBase, Base):
> noncommon2 = Column(Text)
>
> __mapper_args__ = {
> 'polymorphic_identity': 'bar',
> 'concrete': True
> }
>