On May 8, 2007, at 2:41 PM, Gambit wrote:

> Sorry about the wrong subject in the last post. Google groups are  
> quite
> annoying.
>
> This is the minimal program that causes the error:
>
> db = sa.create_engine('mysql://myuser:[EMAIL PROTECTED]/ 
> mydatabase')
> metadata = sa.BoundMetaData(db)
>
> def user_mapper():
>     '''Create the object/relational link for users'''
>     users_table = sa.Table('Users', metadata, autoload=True)
>     sa.orm.clear_mappers()
>     sa.mapper(User, users_table)
>
>     session = sa.create_session(bind_to=db)
>     query = session.query(User)
>
>     return session, query

I see you are creating a Mapper in the same scope as a Session and a  
query.  this is not the proper pattern as mappers are intended to be  
create-once-per-class objects (usually at the module level), whereas  
sessions are usually instantiated once-per-request, queries once-per- 
operation...so those three things do not belong together.  in  
particular clear_mappers() is probably not threadsafe.

> The error I get is:
>
> Database error: (InterfaceError) (0, '') u'SELECT `Users`.`Uid` AS  
> `Users_Uid`, `Users`.`Country` AS `Users_Country`, `Users`.`LName`  
> AS `Users_LName`, `Users`.`Credits` AS `Users_Credits`,  
> `Users`.`Pwd` AS `Users_Pwd`, `Users`.`PhoneNumber` AS  
> `Users_PhoneNumber`, `Users`.`FName` AS `Users_FName`,  
> `Users`.`MoneyBalance` AS `Users_MoneyBalance`, `Users`.`Email` AS  
> `Users_Email` \nFROM `Users` \nWHERE `Users`.`Uid` = %s ORDER BY  
> `Users`.`Uid` \n LIMIT 1' ['testuser']
>
>
> Notice this sometimes works and sometime it doesn't.
>

"sometimes works and sometimes doesnt" screams loudly of thread  
synchronization errors (as does InterfaceError from mysql).  ensure  
that you arent sharing connections or sessions between concurrently  
executing threads.

> This is under mod_python with SQLAlchemy 0.3.7 in case it matters.

another possibility is that the error is occuring corrresponding to  
it being the first thing running within an apache child process.   
again, properly organizing whats module-level vs. whats request level  
should work this out.





--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to