[sqlalchemy] ORM __eq__
Doing this to test equality between ORM objects: a = sess1.query(Thing).get(1) b = sess2.query(Thing).get(1) # different session Was somewhat surprised to find that: a == bgives False Is this by design? Do I need to add a custom __eq__ method to my declarative Base classes to make a==b come out True? Thanks, Michael Hipp -- 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.
Re: [sqlalchemy] ORM __eq__
On Feb 15, 2012, at 12:54 PM, Michael Hipp wrote: Doing this to test equality between ORM objects: a = sess1.query(Thing).get(1) b = sess2.query(Thing).get(1) # different session Was somewhat surprised to find that: a == bgives False Is this by design? Do I need to add a custom __eq__ method to my declarative Base classes to make a==b come out True? Curious, for a and b to be equals without a custom __eq__, that would imply that sess1 and sess2 share the same identity map and state, is that what you were expecting ? Or just that SQLAlchemy would automatically instrument an __eq__() method on mapped classes ? Anyway, yeah we don't assume that, so you'd want to implement an __eq__() that I'd assume compares primary key values. -- 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.
Re: [sqlalchemy] Usage of begin nested
On Feb 15, 2012, at 12:21 AM, Manav Goel wrote: My use case requires that if insertion of object of Myclass succeeds then insert Object of Myclass1 . Even if inserting of Myclass1 object fails insertion of Myclass should not be rolled back. I mean adding Myclass is permanent and does not depend on failure or success of insertion of Myclass1. I have written following code and want to know if am understanding right usage of begin_nested and not writing buggy code. I am using postgresql 9.0 try: obj =Myclass() session.add(obj) if condition true: session.begin_nested() try: n = Myclass1(arguments) session.add(n) except SQLAlchemyError: db_session.rollback() session.commit() except SQLAlchemyError: session.rollback() raise Code is running f9, just want to make sure of some unknown gotcha in this code. Other option will be I commit after adding Myclass and perform insertion of Myclass1 in separate transaction but this way is not appealing to me. assuming that db_session is a typo for session, then yes this is the basic idea.There's a slight gotcha in that you're not inspecting the actual SQLAlchemyError coming in, you might want to limit that to IntegrityError which is what psycopg2 usually throws for these. -- 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.
Re: [sqlalchemy] Full Table scan with Oracle due to Charset conversion
On Feb 15, 2012, at 3:39 PM, Harish Tejwani wrote: Need help! SQL Alchemy: 0.6.8 cx_Oracle: 5.1.1 Red-had Linux Oracle 11gR2, NLS_CHARACTERSET AL32UTF8 Simple Queries like SELECT events.source_name AS events_source_name FROM events WHERE events.source_mac_id = :source_mac_id_1 2012-02-15 10:07:13,061 INFO sqlalchemy.engine.base.Engine.0x...9410 {'source_mac_id_1': u'9911A'} Bind Variables has a 'u' prefixed that causes Oracle to do full TS as it uses SYS_OP_C2C to do conversion and ignores the index on columns. class Event(Base): ''' ''' __tablename__ = events source_name = Column(BigInteger) source_mac_id = Column(String(128)) .. Tried all settings on engine connect side and also changing as below, still no help SQLAlchemy never converts to a u'', however if this is data that's coming back from cx_oracle as a u'' being passed back again, that might be the cause.If you don't pass in a u'' string, then it will remain as a plain bytestring. If you want to force it to encode even when a u'' is passed, use convert_unicode='force': String(128, convert_unicode='force') Though this really seems like a cx_oracle issue. It shouldn't matter if u'' or '' is passed, the end result should be similar and this seems like some kind of Oracle mis-configuration. You might want to ask on the cx_oracle list. -- 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.