[sqlalchemy] Re: column_descriptions on recursive query : AttributeError: 'CTE' object has no attribute 'entity'
Hi The error appears if I do not specify the column name. e.g q = session.query(included_parts) print q.all() print q.column_descriptions included_parts = session.query( Part.sub_part, Part.part, Part.quantity).\ filter(Part.part==our part).\ cte(name=included_parts, recursive=True) incl_alias = aliased(included_parts, name=pr) parts_alias = aliased(Part, name=p) included_parts = included_parts.union_all( session.query( parts_alias.sub_part, parts_alias.part, parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) ''' q = session.query( included_parts.c.sub_part, func.sum(included_parts.c.quantity).label('total_quantity') ).\ group_by(included_parts.c.sub_part) ''' q = session.query(included_parts) print q.all() print q.column_descriptions 2015-04-30 09:52:21,584 INFO sqlalchemy.engine.base.Engine WITH RECURSIVE included_parts(sub_part, part, quantity) AS (SELECT part.sub_part AS sub_part, part.part AS part, part.quantity AS quantity FROM part WHERE part.part = %(part_1)s UNION ALL SELECT p.sub_part AS p_sub_part, p.part AS p_part, p.quantity AS p_quantity FROM part AS p, included_parts AS pr WHERE p.part = pr.sub_part) SELECT included_parts.sub_part AS included_parts_sub_part, included_parts.part AS included_parts_part, included_parts.quantity AS included_parts_quantity FROM included_parts INFO:sqlalchemy.engine.base.Engine:WITH RECURSIVE included_parts(sub_part, part, quantity) AS (SELECT part.sub_part AS sub_part, part.part AS part, part.quantity AS quantity FROM part WHERE part.part = %(part_1)s UNION ALL SELECT p.sub_part AS p_sub_part, p.part AS p_part, p.quantity AS p_quantity FROM part AS p, included_parts AS pr WHERE p.part = pr.sub_part) SELECT included_parts.sub_part AS included_parts_sub_part, included_parts.part AS included_parts_part, included_parts.quantity AS included_parts_quantity FROM included_parts 2015-04-30 09:52:21,586 INFO sqlalchemy.engine.base.Engine {'part_1': 'our part'} INFO:sqlalchemy.engine.base.Engine:{'part_1': 'our part'} [(u'1', u'our part', 1)] ---AttributeError Traceback (most recent call last)ipython-input-8-61b4f7a0eb8b in module() 28 print q.all() 29 --- 30 print q.column_descriptions c:\tg2env27\lib\site-packages\sqlalchemy-1.0.2-py2.7.egg\sqlalchemy\orm\query.pyc in column_descriptions(self) 2580 else None 2581 }- 2582 for ent in self._entities 2583 ] 2584 AttributeError: 'CTE' object has no attribute 'entity' Cheers g On Wednesday, April 29, 2015 at 11:16:54 AM UTC+2, g wrote: Hi all I have a query like that from sqlalchemy.orm import aliased class Part(Base): __tablename__ = 'part' part = Column(String, primary_key=True) sub_part = Column(String, primary_key=True) quantity = Column(Integer) included_parts = session.query( Part.sub_part, Part.part, Part.quantity).\ filter(Part.part==our part).\ cte(name=included_parts, recursive=True) incl_alias = aliased(included_parts, name=pr)parts_alias = aliased(Part, name=p)included_parts = included_parts.union_all( session.query( parts_alias.sub_part, parts_alias.part, parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) q = session.query( included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') ).\ group_by(included_parts.c.sub_part) in sqlalchemy 1.0 we do: q.column_descriptions to get the query columns result is *AttributeError: 'CTE' object has no attribute 'entity'* *Note:* This was working with release 0.9.9 Any idea how to fix it ? Cheers g -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Can I run code when an object is added to a certain relationship?
I have a User model with an association proxy referencing the Email model, so I can access the user's email via user.email. Since I'm soft-deleting users and require emails for non-deleted users to be unique, I have a unique constraint on my email table with a `WHERE not is_user_deleted`. In the User model I have a property that automatically sets email.is_user_deleted when User.is_deleted is set. However, when setting user.email = 'something' for an already deleted user, the association proxy only runs my creator callable UserEmail(email=v) and never sets is_user_deleted=True. Since the user instance if not available within the creator function of the association proxy I wonder if there's any way I can run code whenever something is added to the underlying relationship (User._email), i.e. something like this: @on_stuff_added(User, '_email') def do_stuff(user, email): email.is_user_deleted = user.is_deleted -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Re: Can I run code when an object is added to a certain relationship?
Nevermind. I had to use `set` instead of `append` in the attribute event. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Does anyone know how to handle NoSuchColumnError
Hi, I'm using sqlalchemy 0.9.7 and cx_oracle 5.1.3 and every once in a while (inconsistent), I get the following error: Traceback (most recent call last): File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 1919, in flush self._flush(objects) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2037, in _flush transaction.rollback(_capture_exception=True) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py, line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2001, in _flush flush_context.execute() File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 372, in execute rec.execute(self) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 526, in execute uow File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 65, in save_obj mapper, table, insert) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 602, in _emit_insert_statements execute(statement, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 729, in execute return meth(self, multiparams, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py, line 321, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 826, in _execute_clauseelement compiled_sql, distilled_params File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 978, in _execute_context context._fetch_implicit_returning(result) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py, line 815, in _fetch_implicit_returning ipk.append(row[c]) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py, line 331, in _key_fallback expression._string_or_unprintable(key)) NoSuchColumnError: Could not locate column in row for column 't_shift_employee_change.id' [30/Apr/2015:15:55:17] EXCEPTION # EXCEPTION DESCRIPTION BEGIN # # Type # NoSuchColumnError # Detail # Could not locate column in row for column 't_shift_employee_change.id' # Traceback # File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 1919, in flush self._flush(objects) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2037, in _flush transaction.rollback(_capture_exception=True) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py, line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2001, in _flush flush_context.execute() - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 372, in execute rec.execute(self) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 526, in execute uow - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 65, in save_obj mapper, table, insert) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 602, in _emit_insert_statements execute(statement, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 729, in execute return meth(self, multiparams, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py, line 321, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 826, in _execute_clauseelement compiled_sql, distilled_params - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 978, in _execute_context context._fetch_implicit_returning(result) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py, line 815, in _fetch_implicit_returning ipk.append(row[c]) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py, line 331, in _key_fallback expression._string_or_unprintable(key)) # EXCEPTION DESCRIPTION END # I saw several posts about
Re: [sqlalchemy] Re: column_descriptions on recursive query : AttributeError: 'CTE' object has no attribute 'entity'
On 4/30/15 4:02 AM, g wrote: Hi The error appears if I do not specify the column name. thanks very much! this issue was actually set to go out in 0.9.10 as well, but is now fixed. see https://bitbucket.org/zzzeek/sqlalchemy/issue/3403/0910-10-regression-re-column_descriptions e.g q = session.query(included_parts) print q.all() print q.column_descriptions included_parts = session.query( Part.sub_part, Part.part, Part.quantity).\ filter(Part.part==our part).\ cte(name=included_parts, recursive=True) incl_alias = aliased(included_parts, name=pr) parts_alias = aliased(Part, name=p) included_parts = included_parts.union_all( session.query( parts_alias.sub_part, parts_alias.part, parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) ''' q = session.query( included_parts.c.sub_part, func.sum(included_parts.c.quantity).label('total_quantity') ).\ group_by(included_parts.c.sub_part) ''' q = session.query(included_parts) print q.all() print q.column_descriptions 2015-04-30 09:52:21,584 INFO sqlalchemy.engine.base.Engine WITH RECURSIVE included_parts(sub_part, part, quantity) AS (SELECT part.sub_part AS sub_part, part.part AS part, part.quantity AS quantity FROM part WHERE part.part = %(part_1)s UNION ALL SELECT p.sub_part AS p_sub_part, p.part AS p_part, p.quantity AS p_quantity FROM part AS p, included_parts AS pr WHERE p.part = pr.sub_part) SELECT included_parts.sub_part AS included_parts_sub_part, included_parts.part AS included_parts_part, included_parts.quantity AS included_parts_quantity FROM included_parts INFO:sqlalchemy.engine.base.Engine:WITH RECURSIVE included_parts(sub_part, part, quantity) AS (SELECT part.sub_part AS sub_part, part.part AS part, part.quantity AS quantity FROM part WHERE part.part = %(part_1)s UNION ALL SELECT p.sub_part AS p_sub_part, p.part AS p_part, p.quantity AS p_quantity FROM part AS p, included_parts AS pr WHERE p.part = pr.sub_part) SELECT included_parts.sub_part AS included_parts_sub_part, included_parts.part AS included_parts_part, included_parts.quantity AS included_parts_quantity FROM included_parts 2015-04-30 09:52:21,586 INFO sqlalchemy.engine.base.Engine {'part_1': 'our part'} INFO:sqlalchemy.engine.base.Engine:{'part_1': 'our part'} [(u'1', u'our part', 1)] --- AttributeError Traceback (most recent call last) ipython-input-8-61b4f7a0eb8b inmodule() 28 print q.all()29 --- 30print q.column_descriptionsc:\tg2env27\lib\site-packages\sqlalchemy-1.0.2-py2.7.egg\sqlalchemy\orm\query.pyc in column_descriptions(self) 2580 else None2581 } - 2582for ent in self._entities2583 ] 2584 AttributeError: 'CTE' object has no attribute 'entity' Cheers g On Wednesday, April 29, 2015 at 11:16:54 AM UTC+2, g wrote: Hi all I have a query like that from sqlalchemy.orm import aliased class Part(Base): __tablename__ = 'part' part = Column(String, primary_key=True) sub_part = Column(String, primary_key=True) quantity = Column(Integer) included_parts = session.query( Part.sub_part, Part.part, Part.quantity).\ filter(Part.part==our part).\ cte(name=included_parts, recursive=True) incl_alias = aliased(included_parts, name=pr) parts_alias = aliased(Part, name=p) included_parts = included_parts.union_all( session.query( parts_alias.sub_part, parts_alias.part, parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) q = session.query( included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') ).\ group_by(included_parts.c.sub_part) in sqlalchemy 1.0 we do: q.column_descriptions to get the query columns result is *AttributeError: 'CTE' object has no attribute 'entity'* ** *Note:* This was working with release 0.9.9 Any idea how to fix it ? Cheers g -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving
[sqlalchemy] SQLAlchemy 1.0.3 Released
SQLAlchemy release 1.0.3 is now available. Release 1.0.3 is the latest in a series of weekly releases intended to quickly address remaining small regressions that have come up since the 1.0.0 release. One fairly serious unit-of-work regression regarding SQL expressions is fixed, the new behavior regarding textual expressions with ORDER BY has been scaled back a bit to better suit now-deprecated use cases, a little-used ORM event hook was repaired as it prevented the SQLSoup package from working, and the metadata on create/on drop events experienced a format change in one of the lesser used arguments being passed, which was reverted to its previous form. The release also includes a few additional bug fixes and a series of new features within the connection pool / dialect system to allow for better visibility and customization of the connectivity process. Changelog for 1.0.3 is at: http://www.sqlalchemy.org/changelog/CHANGES_1_0_3 SQLAlchemy 1.0.3 is available on the download page: http://www.sqlalchemy.org/download.html http://www.sqlalchemy.org/download.html -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] prototyping a complex query?
I'll try the selectable. That's a good idea. This won't work as a view -- it'll run too slow. It could be a view of a function, but then it's not really prototyping. I'm trying to figure out an interim solution on the SqlAlchemy side. Right now I'm using some custom objects that re-implement the sqlalchemy relationships based on ids. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Does anyone know how to handle NoSuchColumnError
On 4/30/15 11:00 AM, Ofir Herzas wrote: Hi, I'm using sqlalchemy 0.9.7 and cx_oracle 5.1.3 and every once in a while (inconsistent), I get the following error: Traceback (most recent call last): File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 1919, in flush self._flush(objects) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2037, in _flush transaction.rollback(_capture_exception=True) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py, line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2001, in _flush flush_context.execute() File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 372, in execute rec.execute(self) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 526, in execute uow File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 65, in save_obj mapper, table, insert) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 602, in _emit_insert_statements execute(statement, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 729, in execute return meth(self, multiparams, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py, line 321, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 826, in _execute_clauseelement compiled_sql, distilled_params File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 978, in _execute_context context._fetch_implicit_returning(result) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py, line 815, in _fetch_implicit_returning ipk.append(row[c]) File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py, line 331, in _key_fallback expression._string_or_unprintable(key)) NoSuchColumnError: Could not locate column in row for column 't_shift_employee_change.id' [30/Apr/2015:15:55:17] EXCEPTION # EXCEPTION DESCRIPTION BEGIN # # Type # NoSuchColumnError # Detail # Could not locate column in row for column 't_shift_employee_change.id' # Traceback # File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 1919, in flush self._flush(objects) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2037, in _flush transaction.rollback(_capture_exception=True) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py, line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py, line 2001, in _flush flush_context.execute() - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 372, in execute rec.execute(self) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py, line 526, in execute uow - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 65, in save_obj mapper, table, insert) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py, line 602, in _emit_insert_statements execute(statement, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 729, in execute return meth(self, multiparams, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py, line 321, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 826, in _execute_clauseelement compiled_sql, distilled_params - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py, line 978, in _execute_context context._fetch_implicit_returning(result) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py, line 815, in _fetch_implicit_returning ipk.append(row[c]) - File /opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py, line 331, in _key_fallback expression._string_or_unprintable(key)) # EXCEPTION