Hi Again,

So here's a test case ready to drop onto the end of test_declarative.py:

    def test_mapper_args_single_table(self):

        class TableNameMixin:
            @classproperty
            def __tablename__(cls):
                return cls.__name__.lower()

        class CommonColumns:
            id = Column(Integer, primary_key=True)

        class BaseType(Base, TableNameMixin, CommonColumns):
            discriminator = Column('python_type', String(50))
            __mapper_args__= dict(polymorphic_on=discriminator)
            value = Column(Integer())

        class SpecificType1(BaseType):
            __mapper_args__ = dict(polymorphic_identity='type1')

        class SpecificType2(BaseType):
            __mapper_args__ = dict(polymorphic_identity='type2')

In 0.5.8 with the mixin recipe, this gives:

  File "test_mixable.py", line 459, in test_mapper_args_single_table
    class SpecificType1(BaseType):
  File "mixable.py", line 46, in __init__
    DeclarativeMeta.__init__(cls, classname, bases, dict_)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/ext/declarative.py", line 561, in __init__
    _as_declarative(cls, classname, dict_)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/ext/declarative.py", line 494, in _as_declarative
    *(tuple(cols) + tuple(args)), **table_kw)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/schema.py", line 99, in __call__
    "columns on an existing Table object." % key)
sqlalchemy.exc.InvalidRequestError: Table 'basetype' is already defined for this MetaData instance. Specify 'useexisting=True' to redefine options and columns on an existing Table object.

On trunk, it gives:

======================================================================
ERROR: test.ext.test_declarative.DeclarativeMixinTest.test_mapper_args_single_table
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/Users/chris.withers/sqlalchemy_env/lib/python2.6/site-packages/nose-0.11.3-py2.6.egg/nose/case.py", line 186, in runTest
    self.test(*self.arg)
File "/mnt/Users/chris.withers/sqlalchemy/test/ext/test_declarative.py", line 2228, in test_mapper_args_single_table
    class SpecificType1(BaseType):
File "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py", line 725, in __init__
    _as_declarative(cls, classname, cls.__dict__)
File "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py", line 682, in _as_declarative
    ignore_nonexistent_tables=True)
File "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/sql/util.py", line 205, in join_condition
    "between '%s' and '%s'.%s" % (a.description, b.description, hint))
ArgumentError: Can't find any foreign key relationships between 'basetype' and 'specifictype1'.

*sigh* Any ideas?
(I'll be looking further into this, but thought I'd chuck it at the tlist in case I'm missing anything obvious)

cheers,

Chris

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to