[sqlalchemy] Operational Error
Hi... I am doing my 1st pylon project. I am inserting 2 values in the text boxes and clicking on the ADD(inserting these values in the database)button... Below is the error after clicking on the ADD button. What is the exact reason of this error. plz help me. OperationalError: (OperationalError) no such table: ADD1 u'SELECT count(1) AS count_1 \nFROM ADD1' () -- 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.
[sqlalchemy] Bug in mssql dialect?
Last line is invalid t-sql. The ‘==’ should just be ‘=’. I get the problem when using mssql but not with sqlite. Saw the bug on sqa version 0.6.6, upgraded to 0.7b2 and still having issue. Please let me know if you need more info and I'll be happy to provide. Thanks, Michael Traceback (most recent call last): File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 1133, in module debugger.run(setup['file'], None, None) File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 918, in run execfile(file, globals, locals) #execute the script File C:\OpsPylonDev\TransformationBA-Trunk\pydev-setup-app.py, line 5, in module SetupCommand('setup-app').run(['development.ini']) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 68, in run return super(AbstractInstallCommand, self).run(new_args) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\command.py, line 218, in run result = self.command() File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 456, in command self, config_file, section, self.sysconfig_install_vars(installer)) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 598, in setup_config mod.setup_app, command, filename, section, vars) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 612, in _call_setup_app func(command, conf, vars) File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\websetup.py, line 34, in setup_app insert_data() File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\__init__.py, line 42, in insert_data inserter.insert() File transformationba\model\data\inserters\400technology.py, line 23, in insert csharp_app.create_artifacts() File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\technology_data\csharp_app.py, line 65, in create_artifacts parent.uses.append(component) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 189, in __get__ proxy = self._new(_lazy_collection(obj, self.target_collection)) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 233, in _new self.collection_class = util.duck_type_collection(lazy_collection()) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 335, in __call__ return getattr(obj, self.target) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py, line 162, in __get__ return self.impl.get(instance_state(instance),dict_) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py, line 414, in get value = self.callable_(state, passive) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\strategies.py, line 542, in _load_for_state result = q.all() File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1636, in all return list(self) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1746, in __iter__ return self._execute_and_instances(context) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1752, in _execute_and_instances close_with_result=True).execute(querycontext.statement, self._params) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1259, in execute params) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1392, in _execute_clauseelement compiled_sql, distilled_params File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1500, in _execute_context context) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1493, in _execute_context context) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\default.py, line 325, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)) uSELECT edge.id AS edge_id, edge.tail_node_id AS edge_tail_node_id, edge.head_node_id AS edge_head_node_id, edge._discriminator AS edge__discriminator \nFROM edge \nWHERE edge.tail_node_id = ? AND Edge._discriminator=='use' (69,) -- You received this message because you are subscribed to the
Re: [sqlalchemy] Bug in mssql dialect?
That looks certainly like a misconfigured relationship(). Not sure why SQLite would let it pass through (sqlite is in general extremely liberal), but that's clearly a literal string passed to a join expression sent to relationship as in relationship(... primaryjoin=and_(some expression, Edge._discriminator=='use')) or something like that. When using strings for relationship(), the full expression must be a string, not the components. On Mar 3, 2011, at 10:55 AM, Michael Naber wrote: Last line is invalid t-sql. The ‘==’ should just be ‘=’. I get the problem when using mssql but not with sqlite. Saw the bug on sqa version 0.6.6, upgraded to 0.7b2 and still having issue. Please let me know if you need more info and I'll be happy to provide. Thanks, Michael Traceback (most recent call last): File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 1133, in module debugger.run(setup['file'], None, None) File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 918, in run execfile(file, globals, locals) #execute the script File C:\OpsPylonDev\TransformationBA-Trunk\pydev-setup-app.py, line 5, in module SetupCommand('setup-app').run(['development.ini']) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 68, in run return super(AbstractInstallCommand, self).run(new_args) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\command.py, line 218, in run result = self.command() File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 456, in command self, config_file, section, self.sysconfig_install_vars(installer)) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 598, in setup_config mod.setup_app, command, filename, section, vars) File C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py, line 612, in _call_setup_app func(command, conf, vars) File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\websetup.py, line 34, in setup_app insert_data() File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\__init__.py, line 42, in insert_data inserter.insert() File transformationba\model\data\inserters\400technology.py, line 23, in insert csharp_app.create_artifacts() File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\technology_data\csharp_app.py, line 65, in create_artifacts parent.uses.append(component) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 189, in __get__ proxy = self._new(_lazy_collection(obj, self.target_collection)) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 233, in _new self.collection_class = util.duck_type_collection(lazy_collection()) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py, line 335, in __call__ return getattr(obj, self.target) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py, line 162, in __get__ return self.impl.get(instance_state(instance),dict_) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py, line 414, in get value = self.callable_(state, passive) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\strategies.py, line 542, in _load_for_state result = q.all() File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1636, in all return list(self) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1746, in __iter__ return self._execute_and_instances(context) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py, line 1752, in _execute_and_instances close_with_result=True).execute(querycontext.statement, self._params) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1259, in execute params) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1392, in _execute_clauseelement compiled_sql, distilled_params File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1500, in _execute_context context) File C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py, line 1493, in _execute_context context) File
[sqlalchemy] Unmapped Column Error
Hello all, I've just started using SQLAlchemy recently (and it's been great) but I have run into a problem recently. I am trying to map a table back to itself via a second many-to-many table in a declarative fashion. I have this working as so (mapper configuration): category_association = Table('BankCategoryMap', Base.metadata, Column(ParentCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True), Column(ChildCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True)) category_table = Table('BankCategories', Base.metadata, Column(ID, Integer, primary_key=True), Column(Name, String), Column(Description, String), Column(Active, SmallInteger)) class Category(object): pass mapper(Category, category_table, properties={'parents': relationship(Category, secondary=category_association, primaryjoin=category_table.c.ID == category_association.c.ChildCategoryID, secondaryjoin=category_association.c.ParentCategoryID == category_table.c.ID, backref='children') }) However, when I try it the Declarative way: category_association = Table('BankCategoryMap', Base.metadata, Column(ParentCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True), Column(ChildCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True)) class Category(Base): __tablename__ = 'BankCategories' id = Column(ID, Integer, primary_key=True) name = Column(Name, String) description = Column(Description, String) active = Column(Active, SmallInteger) parents = relationship(Category, secondary=category_association, primaryjoin=BankCategories.ID == category_association.c.ChildCategoryID, secondaryjoin=category_association.c.ParentCategoryID == BankCategories.ID, backref='children') This does not work and I get the following error: File '/home/doug/pyenv_svn/CreateService/surveyservice/surveyservice/ controllers/error.py', line 25 in document cat.parents File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 170 in __get__ instance_dict(instance)) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 390 in get value = callable_(passive=passive) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/strategies.py', line 670 in __call__ result = q.all() File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1576 in all return list(self) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1688 in __iter__ return self._execute_and_instances(context) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1693 in _execute_and_instances mapper=self._mapper_zero_or_none()) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/session.py', line 729 in execute clause, params or {}) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1191 in execute params) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1269 in _execute_clauseelement parameters=params File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1377 in __create_execution_context connection=self, **kwargs) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/default.py', line 388 in __init__ grp,m in enumerate(parameters)] File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/sql/compiler.py', line 291 in construct_params pd[self.bind_names[bindparam]] = bindparam.value() File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/strategies.py', line 447 in lambda state, dict_, bind_to_col[bindparam.key]) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/mapper.py', line 1303 in _get_state_attr_by_column return self._columntoproperty[column]._getattr(state, dict_, column, passive=passive) File
Re: [sqlalchemy] Unmapped Column Error
On Mar 3, 2011, at 5:11 PM, Doug wrote: Hello all, I've just started using SQLAlchemy recently (and it's been great) but I have run into a problem recently. I am trying to map a table back to itself via a second many-to-many table in a declarative fashion. I have this working as so (mapper configuration): However, when I try it the Declarative way: category_association = Table('BankCategoryMap', Base.metadata, Column(ParentCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True), Column(ChildCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True)) class Category(Base): __tablename__ = 'BankCategories' id = Column(ID, Integer, primary_key=True) name = Column(Name, String) description = Column(Description, String) active = Column(Active, SmallInteger) parents = relationship(Category, secondary=category_association, primaryjoin=BankCategories.ID == category_association.c.ChildCategoryID, secondaryjoin=category_association.c.ParentCategoryID == BankCategories.ID, backref='children') You need to use the actual attributes, or a full string, when using the primaryjoin and secondaryjoin arguments. You can't mix and match operators with strings. Some FAQ on a similar issue is here: http://www.sqlalchemy.org/trac/wiki/FAQ#ImusingDeclarativeandsettingprimaryjoinsecondaryjoinusinganand_oror_andIamgettinganerrormessageaboutforeignkeys. This does not work and I get the following error: File '/home/doug/pyenv_svn/CreateService/surveyservice/surveyservice/ controllers/error.py', line 25 in document cat.parents File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 170 in __get__ instance_dict(instance)) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 390 in get value = callable_(passive=passive) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/strategies.py', line 670 in __call__ result = q.all() File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1576 in all return list(self) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1688 in __iter__ return self._execute_and_instances(context) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1693 in _execute_and_instances mapper=self._mapper_zero_or_none()) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/session.py', line 729 in execute clause, params or {}) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1191 in execute params) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1269 in _execute_clauseelement parameters=params File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1377 in __create_execution_context connection=self, **kwargs) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/default.py', line 388 in __init__ grp,m in enumerate(parameters)] File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/sql/compiler.py', line 291 in construct_params pd[self.bind_names[bindparam]] = bindparam.value() File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/strategies.py', line 447 in lambda state, dict_, bind_to_col[bindparam.key]) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/mapper.py', line 1303 in _get_state_attr_by_column return self._columntoproperty[column]._getattr(state, dict_, column, passive=passive) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/mapper.py', line 2510 in __missing__ (column, self.mapper)) UnmappedColumnError: No column :ChildCategoryID_1 is configured on mapper Mapper|Category|BankCategories... Any idea/help on why I'm getting the UnmappedColumnError? Thanks, Doug -- 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
[sqlalchemy] Re: Unmapped Column Error
Thanks for the tip Michael, that solved my problem! It now looks like: category_association = Table('BankCategoryMap', Base.metadata, Column(ParentCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True), Column(ChildCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True)) class Category(Base): __tablename__ = 'BankCategories' id = Column(ID, Integer, primary_key=True) name = Column(Name, String) description = Column(Description, String) active = Column(Active, SmallInteger) parents = relationship(Category, secondary=category_association, primaryjoin=Category.id == BankCategoryMap.c.ChildCategoryID, secondaryjoin=BankCategoryMap.c.ParentCategoryID == Category.id, backref='children') Which works just dandy. Thanks again, Doug On Mar 3, 3:07 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Mar 3, 2011, at 5:11 PM, Doug wrote: Hello all, I've just started using SQLAlchemy recently (and it's been great) but I have run into a problem recently. I am trying to map a table back to itself via a second many-to-many table in a declarative fashion. I have this working as so (mapper configuration): However, when I try it the Declarative way: category_association = Table('BankCategoryMap', Base.metadata, Column(ParentCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True), Column(ChildCategoryID, Integer, ForeignKey('BankCategories.ID'), primary_key=True)) class Category(Base): __tablename__ = 'BankCategories' id = Column(ID, Integer, primary_key=True) name = Column(Name, String) description = Column(Description, String) active = Column(Active, SmallInteger) parents = relationship(Category, secondary=category_association, primaryjoin=BankCategories.ID == category_association.c.ChildCategoryID, secondaryjoin=category_association.c.ParentCategoryID == BankCategories.ID, backref='children') You need to use the actual attributes, or a full string, when using the primaryjoin and secondaryjoin arguments. You can't mix and match operators with strings. Some FAQ on a similar issue is here: http://www.sqlalchemy.org/trac/wiki/FAQ#ImusingDeclarativeandsettingp This does not work and I get the following error: File '/home/doug/pyenv_svn/CreateService/surveyservice/surveyservice/ controllers/error.py', line 25 in document cat.parents File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 170 in __get__ instance_dict(instance)) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/attributes.py', line 390 in get value = callable_(passive=passive) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/strategies.py', line 670 in __call__ result = q.all() File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1576 in all return list(self) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1688 in __iter__ return self._execute_and_instances(context) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py', line 1693 in _execute_and_instances mapper=self._mapper_zero_or_none()) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/session.py', line 729 in execute clause, params or {}) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1191 in execute params) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1269 in _execute_clauseelement parameters=params File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py', line 1377 in __create_execution_context connection=self, **kwargs) File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/default.py', line 388 in __init__ grp,m in enumerate(parameters)] File '/home/doug/pyenv_svn/CreateService/lib/python2.6/site-packages/ SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/sql/compiler.py', line 291 in construct_params
[sqlalchemy] Deadlock in iterating over a session
Hello! I'm iterating over a session to look at all the objects: for obj in session: do_something_cool(obj) Yesterday this caused what looks like a deadlock in SQLAlchemy code. Here is the stack I grabbed using gdb: 1. /python2.5/sqlalchemy/orm/session.py:1353 (Session.__iter__) 2. /python2.5/sqlalchemy/orm/identity.py:184 (WeakInstanceDict.values) 3. /python2.5/sqlalchemy/orm/identity.py:188 (WeakInstanceDict.itervalues ) ** self._remove_mutex.acquire() 4. /python2.5/sqlalchemy/orm/state.py:501 ( MutableAttrInstanceState.__resurrect) 5. /python2.5/sqlalchemy/orm/attributes.py:925 (Events.run) 6. /python2.5/sqlalchemy/orm/mapper.py:2424 (_event_on_resurrect) 7. /python2.5/sqlalchemy/util.py:953 (OrderedSet.__iter__) 8. /python2.5/sqlalchemy/orm/state.py:477 ( MutableAttrInstanceState._cleanup) 9. /python2.5/sqlalchemy/orm/identity.py:139A (WeakInstanceDict.remove)** self._remove_mutex.acquire () I'm running SQLAlchemy 0.6.5. Is this a known issue or am I doing something wrong? On a somewhat related note, am experiencing the issue where lots of objects in a session significantly reduces performance. It appears I am experiencing the penalty for using MutableTypes on objects described here: http://readthedocs.org/docs/sqlalchemy/en/latest/core/types.html#base-type-api. The doc states: In order to detect changes, the ORM must create a copy of the value when it is first accessed, so that changes to the current value can be compared against the “clean” database-loaded value. Additionally, when the ORM checks to see if any data requires flushing, it must scan through all instances in the session which are known to have “mutable” attributes and compare the current value of each one to its “clean” value. It doesn't seem like I should have to pay this penalty because with my type I actually know when any updates occur. The type just supports models.mutable_value.update(data). Is there a way to notify the model/session that the value has been updated when someone calls update, so the full scan of all instances is not needed? Do I need to rewrite the update function to translate models.mutable_value.update(data) to actually generate models.mutable_value = new_mutable_value or is there a better way to do this? Thanks for any help! -Lenza -- 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.