Re: [sqlalchemy] celery and race conditions
On 15 Apr 2014, at 01:12, Jonathan Vanasco jonat...@findmeon.com wrote: i've got that now as a stopgap; i was hoping someone has better ideas. i don't like the idea of a post-commit hook, because i fear requesting the celery task request will create an error. I really don't want to build `transaction` support for celery, but i might need to. That isn't an uncommon scenario; I touched upon that in http://www.wiggy.net/articles/task-queues as well. For rq I am using a variant of https://gist.github.com/wichert/10714681 . One extra problem you need to take into account is that you are likely to run into problems when one of the arguments is a SQLAlchemy ORM instance: when your function is later run in another process that instance won't be associated with the current session, so you need to merge it. Wichert. -- 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] query returns sqlalchemy.util._collections.KeyedTuple. not a maped class instance
Hi there, I m using SQLAlchemy V. 8.6 together with geomalcheny 2.4a second I get a call I have a a mapped class: # tblKey2goGdataLocation # # class tblKey2goGdataLocation(Base): __tablename__ = tblKey2goGdataLocation id = Column(Integer, nullable=False, primary_key=True) location = Column(Geometry('Point')) name = Column( Text ) description = Column( Text ) location_type = Column( Integer ) companies = relation( tblCompany, secondary= tblCompanyLocation.__table__, backref=locations, ) I try to retrieve an maped instance using this query: q = session.query(tblKey2goGdataLocation.__table__) c = tblKey2goGdataLocation.__table__.c q = q.filter(c['id'] == 123) result = q.first() now result is of type: type(result) class 'sqlalchemy.util._collections.KeyedTuple' why? how can I use this element to update the database record? or, how can I get an updatable instance ? thanks very much robert -- 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] query returns sqlalchemy.util._collections.KeyedTuple. not a maped class instance
On Tue, Apr 15, 2014 at 12:06 PM, robert rob...@redcor.ch wrote: Hi there, I m using SQLAlchemy V. 8.6 together with geomalcheny 2.4a second I get a call I have a a mapped class: # tblKey2goGdataLocation # # class tblKey2goGdataLocation(Base): __tablename__ = tblKey2goGdataLocation id = Column(Integer, nullable=False, primary_key=True) location = Column(Geometry('Point')) name = Column( Text ) description = Column( Text ) location_type = Column( Integer ) companies = relation( tblCompany, secondary= tblCompanyLocation.__table__, backref=locations, ) I try to retrieve an maped instance using this query: q = session.query(tblKey2goGdataLocation.__table__) c = tblKey2goGdataLocation.__table__.c q = q.filter(c['id'] == 123) result = q.first() now result is of type: type(result) class 'sqlalchemy.util._collections.KeyedTuple' why? how can I use this element to update the database record? or, how can I get an updatable instance ? I think you want something like this: q = session.query(tblKey2goGdataLocation) q = q.filter(tblKey2goGdataLocation.id == 123) result = q.first() Hope that helps, Simon -- 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] defining a relationship with IS NOT
interesting, i didn't knew that :D i was using shomething like (for softwares such as st2, which has pep8 checking): ## variables NULL = None # f**k pep-8 TRUE = True # f**k pep-8 FALSE = False # f**k pep-8 so, somecol != NULL is not acused as violating pep8, lol. well, just for fun :) On 04/15/2014 02:44 AM, Michael Bayer wrote: there's an isnot() operator, use that On Apr 14, 2014, at 7:17 PM, Jonathan Vanasco jonat...@findmeon.com mailto:jonat...@findmeon.com wrote: I'm on postgres and have a boolean column that allows NULL values. I need to create a relationship between 2 ORM classes , where there is a filter that states IS NOT TRUE. The ORM likes these 2 commands : photo = sa.orm.relationship(Photo, primaryjoin=and_( Useraccount.photo_id==Photo.id , Photo.is http://Photo.is_deletion_scheduled != True )) photo = sa.orm.relationship(Photo, primaryjoin=and_( Useraccount.photo_id==Photo.id , Photo.is http://Photo.is_deletion_scheduled True )) however they don't compare correct in Postgresql. I need this to work, however the mapper doesn't like it: photo = sa.orm.relationship(Photo, primaryjoin=and_( Useraccount.photo_id==Photo.id , Photo.is http://Photo.is_deletion_scheduled IS NOT True )) if I were doing a column comparison, I would do Photo.is http://Photo.is_deletion_scheduled.op('IS NOT')(True) anyone have an idea ? -- 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 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 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] defining a relationship with IS NOT
On 15 Apr 2014, at 13:25, Richard Gerd Kuesters rich...@humantech.com.br wrote: interesting, i didn't knew that :D i was using shomething like (for softwares such as st2, which has pep8 checking): ## variables NULL = None # f**k pep-8 TRUE = True # f**k pep-8 FALSE = False # f**k pep-8 You can also use sqlalchemy.sql.null(), sqlalchemy.sql.true() and sqlalchemy.sql.false() Wichert. -- 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] defining a relationship with IS NOT
yeah, that's why I shared this :) good to know, i'll use that from now on ;) my best regards, richard. On 04/15/2014 09:32 AM, Wichert Akkerman wrote: On 15 Apr 2014, at 13:25, Richard Gerd Kuesters rich...@humantech.com.br mailto:rich...@humantech.com.br wrote: interesting, i didn't knew that :D i was using shomething like (for softwares such as st2, which has pep8 checking): ## variables NULL = None # f**k pep-8 TRUE = True # f**k pep-8 FALSE = False # f**k pep-8 You can also use sqlalchemy.sql.null(), sqlalchemy.sql.true() and sqlalchemy.sql.false() Wichert. -- 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 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] query returns sqlalchemy.util._collections.KeyedTuple. not a maped class instance
On 15 Apr 2014, at 13:06, robert rob...@redcor.ch wrote: Hi there, I m using SQLAlchemy V. 8.6 together with geomalcheny 2.4a second I get a call I have a a mapped class: # tblKey2goGdataLocation # # class tblKey2goGdataLocation(Base): __tablename__ = tblKey2goGdataLocation id = Column(Integer, nullable=False, primary_key=True) location = Column(Geometry('Point')) name = Column( Text ) description = Column( Text ) location_type = Column( Integer ) companies = relation( tblCompany, secondary= tblCompanyLocation.__table__, backref=locations, ) I try to retrieve an maped instance using this query: q = session.query(tblKey2goGdataLocation.__table__) c = tblKey2goGdataLocation.__table__.c q = q.filter(c['id'] == 123) result = q.first() now result is of type: type(result) class 'sqlalchemy.util._collections.KeyedTuple' why? Because you are asking SQLALchemy to return a table object from its query, which is a somewhat odd thing to do. I'm surprised it actually returns anything at all :). Since id is your primary key you can just do this: result = session.query(tblKey2goGdataLocation).get(123) This also won't do an extra SQL query if that object already happens to have been loaded during the current session. if you want to filter on other columns use the filter() method instead: result = session.query(tblKey2goGdataLocation).filter(tblkey2goydatalocation.id == 123).first() Wichert. -- 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] dogpile with SA inheritance
Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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] dogpile with SA inheritance
Hi Pavel, You want: s.query(Person).with_polymorphic(Man).get(51) Cheers, Gulli On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abori...@gmail.com wrote: Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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. -- 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] dogpile with SA inheritance
but I dont know on the time of query what the type of object it will be. On Tuesday, April 15, 2014 5:06:48 PM UTC+4, Gunnlaugur Briem wrote: Hi Pavel, You want: s.query(Person).with_polymorphic(Man).get(51) Cheers, Gulli On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abor...@gmail.comjavascript: wrote: Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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. 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.
Re: [sqlalchemy] dogpile with SA inheritance
On Tue, Apr 15, 2014 at 1:11 PM, Pavel Aborilov abori...@gmail.com wrote: but I dont know on the time of query what the type of object it will be. Then you can use session.query(Person).with_polymorphic('*') to mean joining to the tables of all mapped subclasses. (Be aware that this can become problematic if there is a lot of them.) Cheers, Gulli On Tuesday, April 15, 2014 5:06:48 PM UTC+4, Gunnlaugur Briem wrote: Hi Pavel, You want: s.query(Person).with_polymorphic(Man).get(51) Cheers, Gulli On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abor...@gmail.comwrote: Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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. To post to this group, send email to sqlal...@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. -- 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] celery and race conditions
if i have any time after shipping , i'll probably build in transaction support for celery and pyramid. I keep away from tossing ORM objects around the system. GETS are pretty cheap. my task arguments are generally: int = primary key of ORM object dict = instructions payload of what to do for image processing, it's generally optimize_images( orm_id , { file_b64=BLOB , selected_resizes=[], } ) celery grabs and uses it's own session, pulling data off the database. it optimizes the image, archives it to S3 and does the same for the resizes. then updates the database to reflect all the filesizes and locations. -- 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] defining a relationship with IS NOT
i'll try this later. i ended up 'monkeypatching' all these relationships onto the classes at the end of my models.py file , using the non-string column syntax. would have preferred to keep the entire class definition, together.. but I documented everything. -- 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] dogpile with SA inheritance
I might be wrong, but maybe you could also use eval if you don't know which class at runtime. i.e. session.query(Person).with_polymorphic(eval(classString)) where classString is a string equal to the name of the class. On Tuesday, April 15, 2014 6:56:36 AM UTC-7, Gunnlaugur Briem wrote: On Tue, Apr 15, 2014 at 1:11 PM, Pavel Aborilov abor...@gmail.comjavascript: wrote: but I dont know on the time of query what the type of object it will be. Then you can use session.query(Person).with_polymorphic('*') to mean joining to the tables of all mapped subclasses. (Be aware that this can become problematic if there is a lot of them.) Cheers, Gulli On Tuesday, April 15, 2014 5:06:48 PM UTC+4, Gunnlaugur Briem wrote: Hi Pavel, You want: s.query(Person).with_polymorphic(Man).get(51) Cheers, Gulli On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abor...@gmail.comwrote: Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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. To post to this group, send email to sqlal...@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+...@googlegroups.com javascript:. To post to this group, send email to sqlal...@googlegroups.comjavascript: . 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.
Re: [sqlalchemy] dogpile with SA inheritance
There is a lot of them. But I think it have to be simple. Like a normal query. From the docs I understand how to cache query with FromCache, how to cache relationship with RelationshipCache, but I don't find how to cache polymorphic relationships. On Tuesday, April 15, 2014 5:56:36 PM UTC+4, Gunnlaugur Briem wrote: On Tue, Apr 15, 2014 at 1:11 PM, Pavel Aborilov abor...@gmail.comjavascript: wrote: but I dont know on the time of query what the type of object it will be. Then you can use session.query(Person).with_polymorphic('*') to mean joining to the tables of all mapped subclasses. (Be aware that this can become problematic if there is a lot of them.) Cheers, Gulli On Tuesday, April 15, 2014 5:06:48 PM UTC+4, Gunnlaugur Briem wrote: Hi Pavel, You want: s.query(Person).with_polymorphic(Man).get(51) Cheers, Gulli On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abor...@gmail.comwrote: Hello! How can I cache query like this: session.query(Person).get(51) where 51 is id of Man I can't access attribute age of Man without SELECT. Models: class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } class Man(Person): __tablename__ = 'man' id = Column(Integer, ForeignKey('person.id'), primary_key=True) age = Column(String(100), nullable=False) __mapper_args__ = {'polymorphic_identity': 'man'} -- 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. To post to this group, send email to sqlal...@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+...@googlegroups.com javascript:. To post to this group, send email to sqlal...@googlegroups.comjavascript: . 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.