I'm getting the following error message running TurboGears 2.1.1 and
SQLAlchemy 0.7.2, using TurboGears' multiple database setup described
here:  http://turbogears.org/2.1/docs/main/MultipleDatabases.html.  Both
databases are SQLite3 databases; one is the main database for the
TurboGears app; the other is a Trac 0.11.4 database.  Can you help me
figure out what I'm doing wrong?

InvalidRequestError: One or more mappers failed to initialize - can't
proceed with initialization of other mappers. Original exception was:
When initializing mapper Mapper|WorkDone|work_done, expression 'ticket'
failed to locate a name ("name 'ticket' is not defined"). If this is a
class name, consider adding this relationship() to the <class
'projects.model.main.WorkDone'> class after both dependent classes have
been defined.

In my *model/__init__.py*, I import the model objects in this order (the
traceback makes me think this is the right place to work--either I need
to change the import order here, or add the relation() after the final
import, but neither of these solutions have seemed to work):

from projects.model.trac import *ticket*
from projects.model.main import WorkDone
# To follow the error message's instructions, I tried adding a
relation() here, but it generated a further error; maybe I didn't get
the syntax right.

If I should add a relation immediately above, what is the right syntax? 
But this also seems like a hack to add a relation() here; if I have to
add a relation() here, does that mean my current code has circular
dependencies?

Here's the rest of my relevant code (with important items in bold):

In *projects/model/trac.py*, I have the following (I haven't put any
relation() or backref in this table definition, because this file is
borrowed mostly unmodified from Trac's experimental SQLAlchemy model
object code, and I want to keep it that way):

# begin Tim's modification
from projects.model import metadata2
metadata = metadata2
# end Tim's modification

# Ticket system
*ticket* = Table('ticket', metadata,
        Column('id', Integer, primary_key=True),
        Column('type', Text),
        Column('time', Integer, index=True),
        Column('changetime', Integer),
        Column('component', Text),
        Column('severity', Text),
        Column('priority', Text),
        Column('owner', Text),
        Column('reporter', Text),
        Column('cc', Text),
        Column('version', Text),
        Column('milestone', Text),
        Column('status', Text, index=True),
        Column('resolution', Text),
        Column('summary', Text),
        Column('description', Text),
        Column('keywords', Text))

In *projects/model/main.py*, I have:

class *WorkDone*(DeclarativeBase):
    __tablename__ = 'work_done'
    id = Column(Integer, primary_key=True)
    ticket_id = Column('ticket_id', Integer, ForeignKey('*ticket*.id'))
# many-to-one
    *ticket* = relation('*ticket*', primaryjoin=ticket_id == '*ticket*.id')

The traceback is generated by line 105 of my
*projects/controllers/root.py*, which reads:

for p in DBSession.query(model.*Project*):

*projects/model/main.py* contains:

class *Project*(DeclarativeBase):
    id = Column(Integer, primary_key=True)
    workDone = relation('*WorkDone*') # one-to-many

...and that same class contains several properties that reference the
WorkDone model object like this one does:

    @property
    def totalHours(self):
        return sum([w.elapsed for w in self.*workDone*])

Thank you for any help you can offer!

Tim

-- 
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.

Reply via email to