Re: [sqlalchemy] multiple desktop app issues
На 16.07.2014 19:17 Michael Bayer mike...@zzzcomputing.com написа: On Jul 16, 2014, at 11:02 AM, Vladimir Iliev vladimir.il...@gmail.com wrote: hi, we're developing a desktop app using sa so the sessions is long living. we use postgres and sqlite. if the desktop app is dormant between operations transaction-wise, you might not need to have a long living session pattern. It may be feasible to open up a Session only when interaction with the database is required, within the scope of a transaction. that would over-complicate the code 1. sometimes we see same object twice in one to many relation. it's very hard to reproduce and the problem is gone after commit. does anyone else seen such a behavior? if you append the same object twice to a collection, it will be there twice. When it flushes, relationally this is impossible so only one row actually gets updated; if the collection is then expired and reloaded (as happens on commit()), you'll see just one. I'd recommend using set() for the collection class rather than list. i'm pretty sure i'm not appending anything to collection but i'm updating the other side, so the objects are auto-added to the collection.. 2. sometimes i do ob.relation = [] and repopulate with new entries but after commit the old entries are still there. i can't reproduce it in tests. it only happens while people use the app. the relation is configured with cascade='all,delete-orphan' that would only occur if the change to ob.relation is expired before it is flushed. if some function that occurs within this repopulate happens to call session.commit(), that is one potential way that could happen. the points at which the application calls commit() should be well defined and not arbitrary. it's strange because there are no commits during repopulate. all the code is wrapped in single transaction block. 3. all the write operations are wrapped in with session.begin() blocks but sometimes unhandled error occures (mostly due bugs) and and the session is left in zombie mode. is there a way to auto rollback last transaction in that case? with session.begin() will unconditionally emit a rollback() when an exception is propagated outwards, unless the Session itself no longer has a transaction present, in which case this rollback is not possible. if your application is failing in these blocks, it's very difficult to guarantee that the app can continue running in all cases as the scope of the failure can't be anticipated. A catastrophic failure should probably not be attempting to do anything with the same Session, as it still has state within it that still could be related to the error. There's no way to know, if we're talking about failures with an undefined behavior. 4. what's the right way to modify session state in after insert,update,delete event handler or something similar? for example i have parent object with collection of child objects. i want to recompute in python a column on the parent object whenever child is added,updated or deleted. in most cases triggers are fine but debugging sqlite triggers is driving me nuts... the safest place to calculate changes to related objects in a flush is in the session.before_flush() event. Within the mapper/row-level hooks, it is not safe to interact with related objects, as they may have already been flushed, or are not part of the flush plan. got it. thanks! -- You received this message because you are subscribed to a topic in the Google Groups sqlalchemy group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/vulI27CLD30/unsubscribe. To unsubscribe from this group and all its topics, 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. -- 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] multiple desktop app issues
hi, we're developing a desktop app using sa so the sessions is long living. we use postgres and sqlite. 1. sometimes we see same object twice in one to many relation. it's very hard to reproduce and the problem is gone after commit. does anyone else seen such a behavior? 2. sometimes i do ob.relation = [] and repopulate with new entries but after commit the old entries are still there. i can't reproduce it in tests. it only happens while people use the app. the relation is configured with cascade='all,delete-orphan' 3. all the write operations are wrapped in with session.begin() blocks but sometimes unhandled error occures (mostly due bugs) and and the session is left in zombie mode. is there a way to auto rollback last transaction in that case? 4. what's the right way to modify session state in after insert,update,delete event handler or something similar? for example i have parent object with collection of child objects. i want to recompute in python a column on the parent object whenever child is added,updated or deleted. in most cases triggers are fine but debugging sqlite triggers is driving me nuts... -- 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: multiple desktop app issues
issue 2 - i guess it happens because the relation contents are still referenced in selections after they are marked for deletion or something like that... -- 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] column property problem
Thanks a lot!!! On Monday, June 2, 2014 7:51:56 PM UTC+3, Michael Bayer wrote: oh, I should have even seen this in the compiled SQL, sorry. See that :project_id_1 ? that’s a bound parameter. It’s coming out because when you send the column_property() into the expression like that, it isn’t recognized as a SQL-producing object. If OTOH you passed in “JobItem.project_id” after JobItem were mapped, then it would work because project_id would now be an attribute with a SQL expression set up, but as you can see, you can’t do that right here because you’re still in the class def; this is the improvement to column_property I referred to. Actually this can work as is based on the patch I just added to https://bitbucket.org/zzzeek/sqlalchemy/issue/3050/support-lambdas-strings-in-column_property https://www.google.com/url?q=https%3A%2F%2Fbitbucket.org%2Fzzzeek%2Fsqlalchemy%2Fissue%2F3050%2Fsupport-lambdas-strings-in-column_propertysa=Dsntz=1usg=AFQjCNFXb73ncg1olp1NwrL4o1STisKwmg . But don’t even worry about that patch, workaround right now is just to refer to .expression: @declared_attr def nested_quantity(cls): return column_property( select( [func.sum(NestingSheetLayoutItem.quantity)], ( (cls.project_id.expression==NestingSheetLayout.project_id) (cls.part_id == NestingSheetLayoutItem.part_id) ) ) ) I’ll try to get that patch in for 0.9.5. On Jun 2, 2014, at 6:09 AM, Vladimir Iliev vladimi...@gmail.com javascript: wrote: sorry, i have copy-and-paste incomplete parts of my real model definitions. run the attached file and you will see the exception sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type. u'SELECT (SELECT sum(nestingsheetlayoutitem.quantity) AS sum_1 \nFROM nestingsheetlayoutitem, nestingsheetlayout \nWHERE nestingsheetlayout.project_id = ? AND jobitem.part_id = nestingsheetlayoutitem.part_id) AS anon_1, (SELECT job.project_id \nFROM job \nWHERE job.id = jobitem.job_id) AS anon_2, jobitem.id AS jobitem_id, jobitem.job_id AS jobitem_job_id, jobitem.quantity AS jobitem_quantity, jobitem.part_id AS jobitem_part_id \nFROM jobitem' (ColumnProperty at 0x935c48c; no key,) On Sunday, June 1, 2014 1:47:06 AM UTC+3, Michael Bayer wrote: your example is incomplete in that it is missing named columns such as “part_id” and such, but when I fill those in I’m able to form a SELECT using the properties you refer to: SELECT (SELECT sum(nestingsheetlayoutitem.quantity) AS sum_1 FROM nestingsheetlayoutitem, nestingsheetlayout WHERE nestingsheetlayout.project_id = :project_id_1 AND jobitem.part_id = nestingsheetlayoutitem.part_id) AS anon_1, (SELECT job.project_id FROM job WHERE job.id = jobitem.job_id) AS anon_2, jobitem.id AS jobitem_id, jobitem.job_id AS jobitem_job_id, jobitem.quantity AS jobitem_quantity, jobitem.part_id AS jobitem_part_id FROM jobitem I can see that this query has problems, such as that your column property isn’t equating nestingsheetlayoutitem and nestingsheetlayout to each other and you might be getting too many rows back, but the query is representing as close as I can tell what you’re asking it to render. The subqueries correlate to job_item on the outside, and sometimes there’s extra things needed to make these correlations work out OK but here they seem to be unambiguous. please work with the attached to show more specifically the part that is not working.I will note that column_property does have some configurational limitations within declarative, in that if you wanted to refer to a column_property attached to JobItem directly you have to jump through some extra hoops at the moment, there’s plans to get column_props to be more flexible within declarative. But the mapping here doesn’t seem to be running into those. -- 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 tosqlalchemy+...@googlegroups.com javascript:. To post to this group, send email to sqlal...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. colprop.py -- 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] column property problem
sorry, i have copy-and-paste incomplete parts of my real model definitions. run the attached file and you will see the exception sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type. u'SELECT (SELECT sum(nestingsheetlayoutitem.quantity) AS sum_1 \nFROM nestingsheetlayoutitem, nestingsheetlayout \nWHERE nestingsheetlayout.project_id = ? AND jobitem.part_id = nestingsheetlayoutitem.part_id) AS anon_1, (SELECT job.project_id \nFROM job \nWHERE job.id = jobitem.job_id) AS anon_2, jobitem.id AS jobitem_id, jobitem.job_id AS jobitem_job_id, jobitem.quantity AS jobitem_quantity, jobitem.part_id AS jobitem_part_id \nFROM jobitem' (ColumnProperty at 0x935c48c; no key,) On Sunday, June 1, 2014 1:47:06 AM UTC+3, Michael Bayer wrote: your example is incomplete in that it is missing named columns such as “part_id” and such, but when I fill those in I’m able to form a SELECT using the properties you refer to: SELECT (SELECT sum(nestingsheetlayoutitem.quantity) AS sum_1 FROM nestingsheetlayoutitem, nestingsheetlayout WHERE nestingsheetlayout.project_id = :project_id_1 AND jobitem.part_id = nestingsheetlayoutitem.part_id) AS anon_1, (SELECT job.project_id FROM job WHERE job.id = jobitem.job_id) AS anon_2, jobitem.id AS jobitem_id, jobitem.job_id AS jobitem_job_id, jobitem.quantity AS jobitem_quantity, jobitem.part_id AS jobitem_part_id FROM jobitem I can see that this query has problems, such as that your column property isn’t equating nestingsheetlayoutitem and nestingsheetlayout to each other and you might be getting too many rows back, but the query is representing as close as I can tell what you’re asking it to render. The subqueries correlate to job_item on the outside, and sometimes there’s extra things needed to make these correlations work out OK but here they seem to be unambiguous. please work with the attached to show more specifically the part that is not working.I will note that column_property does have some configurational limitations within declarative, in that if you wanted to refer to a column_property attached to JobItem directly you have to jump through some extra hoops at the moment, there’s plans to get column_props to be more flexible within declarative. But the mapping here doesn’t seem to be running into those. -- 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. from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base, declared_attr Base = declarative_base() class Project(Base): __tablename__ = 'project' id = Column(Integer, autoincrement=True, primary_key=True) class NestingSheetLayout(Base): __tablename__ = 'nestingsheetlayout' id = Column(Integer, autoincrement=True, primary_key=True) project_id = Column(None, ForeignKey(Project.id, ondelete='CASCADE')) project = relationship(Project, backref=backref('nesting_sheet_layouts', cascade='all,delete-orphan', passive_deletes=True)) class NestingSheetLayoutItem(Base): __tablename__ = 'nestingsheetlayoutitem' id = Column(Integer, autoincrement=True, primary_key=True) part_id = Column(Integer) quantity = Column(Integer) nesting_sheet_layout_id = Column(None, ForeignKey(NestingSheetLayout.id, ondelete='CASCADE')) nesting_sheet_layout = relationship(NestingSheetLayout, backref=backref('items', cascade='all,delete-orphan', passive_deletes=True)) @declared_attr def project_id(cls): return column_property( select( [NestingSheetLayout.project_id], NestingSheetLayout.id==cls.nesting_sheet_layout_id ), ) class Job(Base): __tablename__ = 'job' id = Column(Integer, autoincrement=True, primary_key=True) project_id = Column(None, ForeignKey(Project.id)) project = relationship(Project, backref=backref('jobs', cascade='all, delete-orphan')) class JobItem(Base): __tablename__ = 'jobitem' id = Column(Integer, autoincrement=True, primary_key=True) job_id = Column(None, ForeignKey(Job.id, ondelete='CASCADE')) job = relationship(Job, lazy=True, backref=backref('items', cascade='all', passive_deletes=True)) quantity = Column(Integer) part_id = Column(Integer) @declared_attr def project_id(cls): return column_property( select([Job.project_id], Job.id==cls.job_id), ) @declared_attr def nested_quantity(cls): return column_property( select(
[sqlalchemy] column property problem
Hi, i'm trying to add a column property with where clause that depends on other 2 column properties (see JobItem.nested_quantity) in the attached file) but looks like it's not possible. Any ideas if it's possible to achieve same result one way or another ? Thanks -- 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. class Project(DB.Model): id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) class NestingSheetLayout(DB.Model): id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) project_id = sa.Column(None, sa.ForeignKey(Project.id, ondelete='CASCADE')) project = orm.relationship(Project, backref=orm.backref('nesting_sheet_layouts', cascade='all,delete-orphan', passive_deletes=True)) class NestingSheetLayoutItem(DB.Model): id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) quantity = sa.Column(sa.Integer) nesting_sheet_layout_id = sa.Column(None, sa.ForeignKey(NestingSheetLayout.id, ondelete='CASCADE')) nesting_sheet_layout = orm.relationship(NestingSheetLayout, backref=orm.backref('items', cascade='all,delete-orphan', passive_deletes=True)) @declared_attr def project_id(cls): return orm.column_property( sa.select( [NestingSheetLayout.project_id], NestingSheetLayout.id==cls.nesting_sheet_layout_id ), ) class Job(DB.Model): id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) project_id = sa.Column(None, sa.ForeignKey(Project.id)) project = orm.relationship(Project, backref=orm.backref('jobs', cascade='all, delete-orphan')) class JobItem(DB.Model): id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) job_id = sa.Column(None, sa.ForeignKey(Job.id, ondelete='CASCADE')) job = orm.relationship(Job, lazy=True, backref=orm.backref('items', cascade='all', passive_deletes=True)) quantity = sa.Column(sa.Integer) @declared_attr def project_id(cls): return orm.column_property( sa.select([Job.project_id], Job.id==cls.job_id), ) @declared_attr def nested_quantity(cls): return orm.column_property( sa.select( [sa.func.sum(NestingSheetLayoutItem.quantity)], ( (cls.project_id==NestingSheetLayout.project_id) (cls.part_id == NestingSheetLayoutItem.part_id) ) ) )
[sqlalchemy] single table inheritance + composite primary key problem
hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends' __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} type = Column(SmallInteger, primary_key=True) user_id = Column(None, ForeignKey('users.id', ondelete='CASCADE'), primary_key=True) friend_id = Column(None, ForeignKey('users.id', ondelete='CASCADE')) friend_external_id = Column(String(100), primary_key=True) __mapper_args__ = dict( polymorphic_on=type, polymorphic_identity=TYPE_DEFAULT, ) TYPE_FACEBOOK = 2 class FacebookFriend(BaseFriend): __mapper_args__ = dict( polymorphic_identity=TYPE_FACEBOOK, ) User.facebook_friends = relationship(FacebookFriend, lazy=False, primaryjoin=FacebookFriend.user_id==User.id, backref='user' ) when i try to session.query(User).first() i'm getting: New instance FacebookFriend at 0x5b79850 with identity key (class '...Friend.BaseFriend', (2, 75L, u'11288076626')) conflicts with persistent instance FacebookFriend at 0x5c59710 i've tried to define the relationship on both sides with the same results thanks -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/k_QD0fDYRJ0J. 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] Re: single table inheritance + composite primary key problem
p.s. i'm using SA 0.7.1 On Saturday, June 16, 2012 4:37:39 PM UTC+3, Vladimir Iliev wrote: hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends' __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} type = Column(SmallInteger, primary_key=True) user_id = Column(None, ForeignKey('users.id', ondelete='CASCADE'), primary_key=True) friend_id = Column(None, ForeignKey('users.id', ondelete='CASCADE')) friend_external_id = Column(String(100), primary_key=True) __mapper_args__ = dict( polymorphic_on=type, polymorphic_identity=TYPE_DEFAULT, ) TYPE_FACEBOOK = 2 class FacebookFriend(BaseFriend): __mapper_args__ = dict( polymorphic_identity=TYPE_FACEBOOK, ) User.facebook_friends = relationship(FacebookFriend, lazy=False, primaryjoin=FacebookFriend.user_id==User.id, backref='user' ) when i try to session.query(User).first() i'm getting: New instance FacebookFriend at 0x5b79850 with identity key (class '...Friend.BaseFriend', (2, 75L, u'11288076626')) conflicts with persistent instance FacebookFriend at 0x5c59710 i've tried to define the relationship on both sides with the same results thanks -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/LJ6rEcLCLQUJ. 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.
Re: [sqlalchemy] single table inheritance + composite primary key problem
On Saturday, June 16, 2012 4:52:14 PM UTC+3, Michael Bayer wrote: On Jun 16, 2012, at 9:37 AM, Vladimir Iliev wrote: hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends' __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} type = Column(SmallInteger, primary_key=True) user_id = Column(None, ForeignKey('users.id', ondelete='CASCADE'), primary_key=True) friend_id = Column(None, ForeignKey('users.id', ondelete='CASCADE')) friend_external_id = Column(String(100), primary_key=True) __mapper_args__ = dict( polymorphic_on=type, polymorphic_identity=TYPE_DEFAULT, ) TYPE_FACEBOOK = 2 class FacebookFriend(BaseFriend): __mapper_args__ = dict( polymorphic_identity=TYPE_FACEBOOK, ) User.facebook_friends = relationship(FacebookFriend, lazy=False, primaryjoin=FacebookFriend.user_id==User.id, backref='user' ) when i try to session.query(User).first() i'm getting: New instance FacebookFriend at 0x5b79850 with identity key (class '...Friend.BaseFriend', (2, 75L, u'11288076626')) conflicts with persistent instance FacebookFriend at 0x5c59710 Two friends with the same identity key, that is, associated with the same type, user_id (and hence User object), and friend_external_id. I'm not sure what friend_external_id is but if it just refers to some outside source, I doubt you want want the user_id column to be part of the primary key here, that establishes one-to-one, not one-to-many. what i need is friend model with pk (facebook, user id (multiple users might have same external id as friend so it must be part of the key), and friend external id (which in this case is facebook uid)) ... i can probably just use autoincrement integer for primary key but there would be millions friend rows and i prefer if it's tiny. i'm adding and deleting FacebookFriend objects without problems but it fails when i try to session.query(User) with facebook_friends eagerloaded or session.merge(user) if user is loaded from memcached -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/1m3eNDxYORsJ. 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] dynamic relation filtering
hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string thanks in advance --~--~-~--~~~---~--~~ 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] Re: dynamic relation filtering
InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string thanks in advance --~--~-~--~~~---~--~~ 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] Re: dynamic relation filtering
so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string thanks in advance --~--~-~--~~~---~--~~ 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] Re: dynamic relation filtering
ok, thanks Michael Bayer написа: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string thanks in advance --~--~-~--~~~---~--~~ 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] single table inheritance and changing object's type
how can i change the type of mapped object using single table inheritance? thanks --~--~-~--~~~---~--~~ 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] question
hi, i have a method that returns list of (material, thickness) groups which looks like: C = [order_element_items.c.material_uuid, materials.c.name, order_element_items.c.thickness] S = select( C, order_element_items.c.material_uuid==materials.c.uuid, from_obj=[order_element_items, materials], order_by=[materials.c.name, order_element_items.c.thickness], group_by=C, ) res = [(session.query(Material).filter_by(uuid=a).one(), c) for a,b,c in session.bind.execute(S)] but it does too many selects and i wonder is it possible somehow to achieve the same result with one select? thanks in advance --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] dynamic relations
hi, what's wrong with the attached example? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- from sqlalchemy import * from sqlalchemy.orm import * metadata = MetaData('sqlite://') #~ metadata.bind.echo = 'debug' companies = Table('companies', metadata, Column('company_id', Integer, primary_key=True), Column('name', String(50))) employees_table = Table('employees', metadata, Column('employee_id', Integer, primary_key=True), Column('company_id', Integer, ForeignKey('companies.company_id')), Column('name', String(50)), ) metadata.create_all() class Person(object): def __init__(self, **kwargs): for key, value in kwargs.iteritems(): setattr(self, key, value) def __repr__(self): return Ordinary person %s % self.name class Company(object): def __init__(self, **kwargs): for key, value in kwargs.iteritems(): setattr(self, key, value) def __repr__(self): return Company %s % self.name company_mapper = mapper(Company, companies) person_mapper = mapper(Person, employees_table, properties={ 'company': relation(Company, backref=backref('employees', lazy='dynamic')) }) session = create_session() c = Company(name='company1') c.employees.append(Person(name='joesmith')) session.save(c) session.flush() session.clear() c = session.query(Company).get(1) print c.employees print list(c.employees) print c.employees.count() metadata.drop_all()
[sqlalchemy] Re: dynamic relations
i'm glad you're always so responsive ;-) Michael Bayer написа: im glad people are finally using dynamic relationstry out rev 3869. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] column_property() caching
hi, is it possible to add a non-caching column_property() to my mapping? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---