Issues

Issue #2194 resolved

odd check for name in decl determining inheritance

Mike Bayer
repo owner created an issue
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
   __tablename__ = "a"
   id = Column( Integer, primary_key=True)
a_1 = A
class A(a_1):
   __tablename__ = 'b'

   id = Column(Integer(),ForeignKey(a_1.id), primary_key = True)

patch:

diff -r eaa7aa4239af4f42cdb8b370120d1538c6704d6b lib/sqlalchemy/ext/declarative.py
--- a/lib/sqlalchemy/ext/declarative.py Sun Jun 12 20:35:37 2011 -0400
+++ b/lib/sqlalchemy/ext/declarative.py Tue Jun 14 10:02:39 2011 -0400
@@ -1038,8 +1038,7 @@
     if 'inherits' not in mapper_args:
         for c in cls.__bases__:
             if _is_mapped_class(c):
-                mapper_args['inherits']('inherits') = cls._decl_class_registry.get(
-                                                            c.__name__, None)
+                mapper_args['inherits']('inherits') = c
                 break

     if hasattr(cls, '__mapper_cls__'):

it appears the logic above was from a check to ensure that the superclass was also part of the declarative base. It would be exceedingly rare that someone mapped a class, then used it as a mixin and didn't want joined inh to occur, so this check can probably be removed.

Comments (2)

  1. Log in to comment