Hi everyone, so sorry if this is a noob question (actually I'm a
newbie) but I already searched quite a bit without finding an useful
tip. I'm using pylons 0.9.7
I'm building a data warehouse front end with pylons and for this, I
found very useful SqlAlchemy's reflection feature. I place all the
mappers in reports/models/__init__.py following the stub I found right
there when I started the project. I played a little bit with paster
shell and so far it's working great. The thing is that I quickly
decided to start building my tests before my model gets bigger and
when I try to run it (I didin't even added a proper test) I hit the
following error:

ArgumentError: Class '<class 'repotrs.model.User'>' already has a
primary mapper defined. Use non_primary=True to create a non primary
Mapper.  clear_mappers() will remove *all* current mappers from all
classes.
See below a little example of __init__.py:

_________________________________________________________
"""The application's model objects"""

import sqlalchemy as sa
from sqlalchemy import orm

from repotrs.model import meta

def init_model(engine):
    """Call me before using any of the tables or classes in the
model"""
    ## Reflected tables must be defined and mapped here
    global t_users
    t_users = sa.Table("users", meta.metadata, autoload=True,
                               autoload_with=engine)
    orm.mapper(User, t_users)
    #
    meta.Session.configure(bind=engine)
    meta.engine = engine


## Non-reflected tables may be defined and mapped at module level
#foo_table = sa.Table("Foo", meta.metadata,
#    sa.Column("id", sa.types.Integer, primary_key=True),
#    sa.Column("bar", sa.types.String(255), nullable=False),
#    )
#
#class Foo(object):
#    pass
#
#orm.mapper(Foo, foo_table)


## Classes for reflected tables may be defined here, but the table and
## mapping itself must be done in the init_model function
t_users = None

class User(object):
    pass
__________________________________________________________


In the nosetest error trace I can see init_model is called in repotrs/
config/environment.py but it seems imposible to find out why it's
given the error.

TIA,
Mariano.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to