Hi,

I am having a problem with declarative and inheritance from a class
which has the same name, but different namespace (module):

=======================================> names.py <==
# Fails with Python-2.7.1 and SQLAlchemy-0.7.1
# 

import sqlalchemy
import sqlalchemy.ext.declarative

Base = sqlalchemy.ext.declarative.declarative_base()

engine = sqlalchemy.create_engine('sqlite:///:memory:', echo = False)

session = sqlalchemy.orm.scoped_session(
    sqlalchemy.orm.sessionmaker(
        bind = engine,
        autocommit = False
    )
)

Base.metadata.bind = engine

class SomeObj(Base):
    __tablename__ = "someobj"
    Id = sqlalchemy.Column( sqlalchemy.types.Integer, primary_key=True,
autoincrement=True)
    objType = sqlalchemy.Column(sqlalchemy.types.String(128), index =
True, nullable = False)
    __mapper_args__ = {
        'polymorphic_identity': __tablename__,
        'polymorphic_on': objType
    }

import bar


=======================================> foo.py <==
import sqlalchemy
import names

class Foo(names.SomeObj):
    __tablename__ = 'foo_foo'

    Id = sqlalchemy.Column(
        sqlalchemy.types.Integer(),
        sqlalchemy.schema.ForeignKey(names.SomeObj.Id),
        primary_key = True
    )

    mapper_args = {
        'inherit_condition': Id == names.SomeObj.Id,
        'polymorphic_identity': __tablename__,
    }


=======================================> bar.py <==
import sqlalchemy
import foo

class Foo(foo.Foo):
    __tablename__ = 'bar_foo'

    Id = sqlalchemy.Column(
        sqlalchemy.types.Integer(),
        sqlalchemy.schema.ForeignKey(foo.Foo.Id),
        primary_key = True
    )

    mapper_args = {
        'inherit_condition': Id == foo.Foo.Id,
        'polymorphic_identity': __tablename__,
    }

=====================================


After running names.py I get:
=====================================
/home/filip/tefnet/teferp/workspace/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/ext/declarative.py:1129:
 SAWarning: The classname 'Foo' is already in the registry of this declarative 
base, mapped to <class 'foo.Foo'>
  _as_declarative(cls, classname, cls.__dict__)
Traceback (most recent call last):
  File "names.py", line 29, in <module>
    import bar
  File "/home/filip/tefnet/teferp/bugs/names/bar.py", line 4, in
<module>
    class Foo(foo.Foo):
  File
"/home/filip/tefnet/teferp/workspace/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/ext/declarative.py",
 line 1129, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File
"/home/filip/tefnet/teferp/workspace/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/ext/declarative.py",
 line 1059, in _as_declarative
    compile=False)
  File
"/home/filip/tefnet/teferp/workspace/tefobjects/lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg/sqlalchemy/orm/util.py",
 line 546, in class_mapper
    raise exc.UnmappedClassError(class_)
sqlalchemy.orm.exc.UnmappedClassError: Class 'bar.Foo' is not mapped
=====================================

despite separate namespaces.
Is there some way I could make the mapper aware of namespaces?

PS. Zzzeek - thanks for sorting out the count() thing before :).

regards,
Filip Zyzniewski
Tefnet

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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.

Attachment: names.tbz2
Description: application/bzip-compressed-tar

Reply via email to