[sqlalchemy] order of operations question
Hi All, If I do: obj = session.query(MyModel).one() obj.attr = 'something' session.add(MyModel(attr='else')) session.commit() ...does sqlalchemy guarantee that the update will happen before the insert? cheers, Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] wiring in events as part of a declarative mixin
Hi All, I'd like to wire in a listener for before_insert for all models that use a particular mixin. I may need to construct the listener based on some columns in both the mixin and the model that mixes it in. Do I use declared_attr and __declare_last__? Are there any examples around of doing this? cheers, Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] ORM query with overlaps operator
This solution seems to work in my context Thanks Gio Am Mittwoch, 8. Mai 2013 16:18:31 UTC+2 schrieb Michael Bayer: from sqlalchemy.sql import column, tuple_ a, b = column('a'), column('b') print tuple_(a, b).op(OVERLAPS)(tuple_(1, 2)) (a, b) OVERLAPS (:param_1, :param_2) On May 8, 2013, at 6:39 AM, gio giovanni...@auditq.com javascript: wrote: Hi all Searching how to solve the (start,end).op('OVERLAPS')(,start1,end1) Problem with postgres and salqalchemy 0.8 Some hints ? Note: _CompareMixin is not presen in SQLalchem 0.8 Am Freitag, 21. August 2009 09:50:10 UTC+2 schrieb David Bolen: Has anyone generated ORM queries using the OVERLAPS SQL operator that reference columns in the tables in the query? I've been experimenting with various approaches and can't seem to cleanly get the column names (with their appropriate alias based on the rest of the query) into the overlaps clause. I'm basically issuing an ORM query and want to check that the date range given by two columns in one of the objects being queried is overlaps with a computed date range. In some cases the object whose columns I am checking is the primary target of the query whereas in others it's a joined class. I found an older post from March where Michael suggested the form somexpression.op('OVERLAPS', someotherexpression) but I can't figure out how to apply that, and in particular what sort of expression will produce a tuple at the SQL layer, yet still support the op method? Namely the output needs to be of the form: (start, stop) OVERLAPS (start, stop) So I figured I'd try straight text, and was attempting something like: query(MappedClass). filter('(:c_start, :c_end) overlaps (:start, :end)'). params(c_start=MappedClass.start_col, c_end=MappedClass.end_col, start=datetimevalue, end=datetimevalue) but I'm having trouble identifying an appropriate value for the c_start/c_end params to generate the column names in the resulting SQL. The above gives can't adapt the InstrumentedAttribute references in the params. In the meantime I can fall back to a pure textual filter which will have to assume how the mapped class will be aliased, but that feels fragile and it'd be nice if I could let SQLAlchemy generate the column names somehow. I get the feeling though that OVERLAPS is a bit unusual in terms of the necessary support since it has non-scalar left and right values for the operator. Thanks for any help. -- David -- 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+...@googlegroups.com javascript:. To post to this group, send email to sqlal...@googlegroups.comjavascript: . Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] Possible regression from 0.7.9 to 0.8.0
I have the following code: from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session, relationship, backref e = create_engine('sqlite:tmp/test.db', echo=True) Base = declarative_base() Base.metadata = MetaData(e) class Node(Base): __tablename__ = 'nodes' id = Column(Integer, primary_key=True) class Item(Base): __tablename__ = 'items' id = Column(Integer, primary_key=True) node_id = Column(Integer, ForeignKey(Node.id)) item_type = Column(String(24), default='item') node = relationship(Node, lazy=True, uselist=False, backref=backref('objects', lazy=True, uselist=True)) __mapper_args__ = { 'polymorphic_identity': 'item', 'polymorphic_on': 'item_type', 'with_polymorphic': '*', } class PolyItem(Item): __tablename__ = 'poly_items' id = Column(Integer, ForeignKey(Item.id), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'polyitem', } item = relationship(Item, lazy=True) if __name__ == '__main__': Base.metadata.drop_all() Base.metadata.create_all() node = Node() item = PolyItem(node=node) session = Session(e) session.add(node) session.add(item) session.commit() node = session.query(Node).first() session.delete(node) session.commit() This runs fine in 0.7.9 and 0.8.0. However, if I change PolyItem.item to relationship(Item, lazy=False), 0.7.9 continues to function, while 0.8.0 and 0.8.1 go into infinite loops and eventually fail due to maximum recursion exceeded. The adding to the db works, it's the delete that is failing. I've already worked around it on my end (lazy=False seems of little use here, and was being added programatically, so I adjusted it there and it seems okay), but I figured I'd point it out as the behavior changed pretty radically between those 2 versions. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] Possible regression from 0.7.9 to 0.8.0
this is a reopen of http://www.sqlalchemy.org/trac/ticket/2481, and is fixed again in r7699a1080742. Thanks for the report. On May 13, 2013, at 3:18 PM, Gerald Thibault dieselmach...@gmail.com wrote: I have the following code: from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session, relationship, backref e = create_engine('sqlite:tmp/test.db', echo=True) Base = declarative_base() Base.metadata = MetaData(e) class Node(Base): __tablename__ = 'nodes' id = Column(Integer, primary_key=True) class Item(Base): __tablename__ = 'items' id = Column(Integer, primary_key=True) node_id = Column(Integer, ForeignKey(Node.id)) item_type = Column(String(24), default='item') node = relationship(Node, lazy=True, uselist=False, backref=backref('objects', lazy=True, uselist=True)) __mapper_args__ = { 'polymorphic_identity': 'item', 'polymorphic_on': 'item_type', 'with_polymorphic': '*', } class PolyItem(Item): __tablename__ = 'poly_items' id = Column(Integer, ForeignKey(Item.id), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'polyitem', } item = relationship(Item, lazy=True) if __name__ == '__main__': Base.metadata.drop_all() Base.metadata.create_all() node = Node() item = PolyItem(node=node) session = Session(e) session.add(node) session.add(item) session.commit() node = session.query(Node).first() session.delete(node) session.commit() This runs fine in 0.7.9 and 0.8.0. However, if I change PolyItem.item to relationship(Item, lazy=False), 0.7.9 continues to function, while 0.8.0 and 0.8.1 go into infinite loops and eventually fail due to maximum recursion exceeded. The adding to the db works, it's the delete that is failing. I've already worked around it on my end (lazy=False seems of little use here, and was being added programatically, so I adjusted it there and it seems okay), but I figured I'd point it out as the behavior changed pretty radically between those 2 versions. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] textcolumn.contains() escaping, the lack of icontains(), and possible bug?
On May 13, 2013, at 6:30 PM, Daniel Grace thisgenericn...@gmail.com wrote: So today I identified a small bug in my code and then, while trying to resolve it, came to a few realizations: 1. column.contains(str) does not escape characters in str such as % and _. Presumably, column.startswith(str) and column.endswith(str) have the same behavior. this will be called autoescape and is ticket 2694: http://www.sqlalchemy.org/trac/ticket/2694 .if someone wants to work on a patch for this it would be v. helpful. It's a little late to turn on the escaping for all users now as it would break existing workarounds. 2. There is a distinct lack of column.icontains(str), though the current implementation means it's identical to column.ilike('%' + str + '%') since we do have ilike() as an operator icontains() would be appropriate at this point (also startswith,endswith). 3. There is no builtin function (that I found, please correct me if I'm wrong!) for escaping a string being passed to any functions in this family. will be 2694 While I think that column.like and column.ilike should definitely /not/ escape their argument (you know you're trying for a pattern match here, and that you're matching against a pattern), I think that the .contains/.startswith/.endswith family of functions probably should perform this escaping transparently. Between DBAPI 2.0, SQLAlchemy and parameterized querying I don't need to worry about escaping input, so why should I have to pay attention to that detail when using .contains? Also, case insensitive versions of the above would probably be useful. That said, a proper fix might be complicated since it could inadvertently break existing code that relies on the current behavior of .contains() -- Daniel -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] textcolumn.contains() escaping, the lack of icontains(), and possible bug?
Good to hear! I took a look at #2694 and it seems that using column.contains(other, autoescape=True) might get wordy fairly quick when -- at least in new applications -- it would be a handy default. While it's probably not particularly feasible, it'd be handy if the default for autoescape could somehow be set on a engine/metadata/etc level. -- Daniel -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] EAV Optimizations
A few months ago I watched a video conference where Mike demo'd some optimizations for SQLAlchemy when using EAV schemas. Does anyone know if these optimizations will make it into the product that we have access to? I'm about to start a large EAV based project with SA and I was curious. Mike -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] EAV Optimizations
what video is that ?I don't use EAV's too often. If you can point me to something I can identify what it was. On May 13, 2013, at 8:22 PM, Lycovian mfwil...@gmail.com wrote: A few months ago I watched a video conference where Mike demo'd some optimizations for SQLAlchemy when using EAV schemas. Does anyone know if these optimizations will make it into the product that we have access to? I'm about to start a large EAV based project with SA and I was curious. Mike -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.