On Jan 10, 2012, at 11:38 AM, Josh Ha-Nyung Chung wrote:

> I'm running web service using sqlalchemy with apache + wsgi + pyramid 
> framework.
> I've initialize metadata like the following:
> 
> Base = declarative_base()
> Base.metadata.reflect(bind=my_engine)
> user_table = DP_Base.metadata.tables["user"]
> mapper(User, user_table)
> 
> and I'm using scoped session since I'm running apache+wsgi with multiple 
> processes and threads.
> weird thing is that, errors occur sometimes saying
> 
> ArgumentError: Class '<class 'mypackage.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.
> 
> Once the error occurs, all the following requests to the web service 
> encounter the same errors. Restarting httpd  seems to resolve the problem 
> temporarily.
> 
> I'm afraid that I'm using reflection and mapping in the wrong way? or Is 
> there something that I have to care about among multi-threaded, scoped 
> session, and table mapping?
> 
> 

does User extend Base ?  In that case, it's already mapped.   Unless you have a 
real need to use classical mappings there's no need to use mapper() (would be 
also curious what lead to that decision as it may be a documentation issue).   


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