this is something related to how turbogears is integrating  
SQLAlchemy.  there might be a bug in SA here but I cant track it down  
without an example that shows what TG is doing more specifically.  in  
particular i hope they are using the QueuePool connection pool and  
not the SingletonThreadPool....the error involves a cursor being  
shared between two conflicting states.


On Feb 20, 2007, at 10:12 AM, Brad Lindsay wrote:

> I'm new to SQLAlchemy, and am currently using it for Turbogears  
> developement.  I've run into an issue calling delete on an  
> instance. This almost exact same code works fine in one of my  
> projects, but I get an error in this particular one.  I think it  
> may have be because this is a many-to-many relationship while the  
> other one is simply a many-to-one relationship.  I think there's  
> something I'm missing, and was hoping someone might be able to see  
> what it was.
>
> Thanks,
> Brad
>
> Here's the setup:
> ===================
> questions_table = Table('questions', metadata,
>     Column('id', Integer, primary_key=True),
>     Column('interrogative', Unicode(255), nullable=False),
>     Column('sort_order', Integer, nullable=False, default=0)
> )
>
> choices_table = Table('choices', metadata,
>     Column('id', Integer, primary_key=True),
>     Column('a_choice', Unicode(255), nullable=False)
> )
>
> choices_questions_table = Table('choices_questions', metadata,
>     Column('question_id', Integer, ForeignKey('questions.id')),
>     Column('choice_id', Integer, ForeignKey(' choices.id'))
> )
>
> class Question(object):
>     """The Question class."""
>     def __init__(self, interrogative, order):
>         self.interrogative = interrogative
>         self.sort_order = order
>
> class Choice(object):
>     """The Choice class."""
>     def __init__(self, a_choice):
>         self.a_choice = a_choice
>
> assign_mapper(session.context, Question, questions_table,
>         properties=dict(choices=relation(Choice,  
> secondary=choices_questions_table, backref='questions')))
>
> assign_mapper(session.context, Choice, choices_table)
>
>
> Here's the function that's having problems:
> ======================================
> def q_delete(self, qid):
>     del_q = Question.get(int(qid))
>     Question.delete(del_q)
>     raise redirect("/admin")
>
>
> Here's the error:
> =====================
> Page handler: <bound method AdminController.q_delete of  
> <neognosis.controllers.AdminCont
> roller object at 0x2151490>>
> Traceback (most recent call last):
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/CherryPy- 2.2.1-py2.4.egg/cherrypy/ 
> _cphttptools.py", line 105, in _run
>     self.main()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/ 
> _cphttptools.py", line 254, in main
>     body = page_handler(*virtual_path, **self.params)
>   File "<string>", line 3, in q_delete
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/TurboGears- 1.0-py2.4.egg/turbogears/ 
> controllers.py", line 334, in expose
>     output = database.run_with_transaction(
>   File "<string>", line 5, in run_with_transaction
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/TurboGears- 1.0-py2.4.egg/turbogears/ 
> database.py", line 305, in sa_rwt
>     retval = dispatch_exception(e,args,kw)
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/TurboGears-1.0-py2.4.egg /turbogears/ 
> database.py", line 303, in sa_rwt
>     transaction.commit()
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/session.py",  
> line 54, in commit
>   File "build/bdist.macosx-10.3-fat /egg/sqlalchemy/orm/ 
> session.py", line 220, in flush
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> unitofwork.py", line 194, in flush
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> unitofwork.py", line 321, in execute
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> unitofwork.py", line 771, in preexecute
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> dependency.py", line 176, in preprocess_dependencies
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> dependency.py", line 99, in get_object_dependencies
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> attributes.py", line 686, in get_history
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> attributes.py", line 85, in get_history
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/ 
> attributes.py", line 183, in get
>   File "build/bdist.macosx- 10.3-fat/egg/sqlalchemy/orm/ 
> strategies.py", line 220, in lazyload
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/query.py",  
> line 254, in select_whereclause
>   File "build/bdist.macosx-10.3-fat /egg/sqlalchemy/orm/query.py",  
> line 380, in _select_statement
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/query.py",  
> line 312, in execute
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/orm/query.py",  
> line 330, in instances
>   File "build/bdist.macosx-10.3-fat/egg/sqlalchemy/engine/base.py",  
> line 671, in fetchall
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/MySQLdb/cursors.py", line 258, in fetchall
>     self._check_executed()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/MySQLdb/cursors.py", line 54, in  
> _check_executed
>     self.errorhandler(self, ProgrammingError, "execute() first")
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
> python2.4/site-packages/MySQLdb/connections.py", line 33, in  
> defaulterrorhandler
>     raise errorclass, errorvalue
> ProgrammingError: execute() first
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to