[sqlalchemy] Re: r3507 breaks here
ive grepped all the code and cannot find a create_row_processor method that is returning a 2-tuple (which is what it used to be); theyre all returning 3-tuples..and of course all those methods have test coverage too. have you tried deleting all the .pyc files to ensure all python modules have recompiled ? On Sep 24, 2007, at 1:39 AM, [EMAIL PROTECTED] wrote: hi. r3506 is still ok, while r3507 gives this: result: [] expected: [35] SAMPLE: 2006-09-11 00:00:00 2006-09-12 00:00:00 2006-09-14 00:00:00 [35] 'trans exact, valids between _2' FROM test_range TimedRangeTestCase -- Traceback (most recent call last): ... File test_timed_dbcook.py, line 142, in _get_range_val q = me.val.get_obj_history_in_range( me.val.OBJ_ID, timeFrom, timeTo).all() File /home/az/src/hor-trunk/sqlalchemy/orm/query.py, line 571, in all return list(self) File /home/az/src/hor-trunk/sqlalchemy/orm/query.py, line 619, in __iter__ return self._execute_and_instances(statement) File /home/az/src/hor-trunk/sqlalchemy/orm/query.py, line 624, in _execute_and_instances return iter(self.instances(result)) File /home/az/src/hor-trunk/sqlalchemy/orm/query.py, line 680, in instances self.select_mapper._instance(context, row, result) File /home/az/src/dbcook/sqlalchemy/orm/mapper.py, line 1436, in _instance self.populate_instance(context, instance, row, **flags) File /home/az/src/dbcook/sqlalchemy/orm/mapper.py, line 1496, in populate_instance (newpop, existingpop, post_proc) = prop.create_row_processor(selectcontext, self, row) ValueError: need more than 2 values to unpack the result query is somewhat awwful, but it works before that: -- TEST trans exact, valids between _2* SA: INFO SELECT PolymBase.disabled AS PolymBase_disabled, PolymBase.val AS PolymBase_val, PolymBase.time_valid AS PolymBase_time_valid, PolymBase.time_trans AS PolymBase_time_trans, PolymBase.obj_id AS PolymBase_obj_id, PolymBase.atype AS PolymBase_atype, PolymBase.db_id AS PolymBase_db_id, PolymLeaf.db_id AS PolymLeaf_db_id FROM ( SELECT max(PolymBase.db_id) AS db_id, PolymBase.time_trans AS time_trans, PolymBase.time_valid AS time_valid FROM PolymBase JOIN ( SELECT max(PolymBase.time_trans) AS time_trans, PolymBase.time_valid AS time_valid FROM PolymBase WHERE PolymBase.time_trans = ? AND PolymBase.time_valid = ? AND PolymBase.time_valid = ? AND PolymBase.obj_id = ? AND PolymBase.atype = ? GROUP BY PolymBase.time_valid ) AS t1 ON PolymBase.time_valid = t1.time_valid AND PolymBase.time_trans = t1.time_trans WHERE PolymBase.obj_id = ? AND PolymBase.atype = ? GROUP BY PolymBase.time_valid, PolymBase.time_trans ) AS timedr, PolymBase JOIN PolymLeaf ON PolymLeaf.db_id = PolymBase.db_id WHERE PolymBase.db_id = timedr.db_id AND NOT PolymBase.disabled ORDER BY PolymBase.time_valid * SA: INFO [11, 12, 14, 1, 'PolymLeaf', 1, 'PolymLeaf'] any idea? i mau try prepare some stripped testcase but it'll take time... if u wanna try, svn co then run make in https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/misc/ timed2/test/ or do PYTHONPATH=..:../../../..:../../..:$(PYTHONPATH) python test_timed_dbcook.py svil --~--~-~--~~~---~--~~ 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] Re: db independent way to get id from sequence
please help --~--~-~--~~~---~--~~ 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] detect if objects have been deleted from a session?
Hello. I have a naive system that links dict-like objects to mapped classes so that rows can be saved to the db. It doesn't know anything about mapped class instances, so many-to-many relationships are [currently] saved by a class mapped to the swing table itself; for example, it's the equivalent of : client_role = Role(role_name=client) acme = Organization( organization_name=Acme) acme_is_a_client = OrganizationRoles( organization_id = acme.id, role_id = client_role.id) The deletion process iters through from child to parent according to foreign keys and performs : session.delete(acme_is_a_client) session.delete(acme) session.delete(client_role) However, if somewhere in the app Organization.query().join('roles').select() was performed, then deleting acme will fail because it would have been deleted automatically by session.delete(acme_is_a_client). Specifically, I get a ConcurrentModificationError saying the deleted row count was 0. Given the limitation of this approach and not trying to depend on the configuration of ondelete/passive_deletes, is it possible to simply detect whether or not acme or client_role has been deleted in the session before deleting? That is, something more like : if not object_was_deleted(session, acme_is_a_client): session.delete(acme_is_a_client) if not object_was_deleted(session, acme): # this should not be executed session.delete(acme) if not object_was_deleted(session, client_role): # nor this session.delete(client_role) The implementation below seems to detect deletions of the same object but *not* the above scenario where the objects deleted were children : def object_was_deleted(session, obj): from sqlalchemy.orm.mapper import object_mapper for c in [obj] + list(object_mapper(obj).cascade_iterator( 'delete', obj)): if c in session.uow.deleted: return True elif not session.uow._is_valid(c): return True return False Is there a way to detect deleted children? Thanks for reading and let me know if you need a more concrete example -Kumar --~--~-~--~~~---~--~~ 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] Re: db independent way to get id from sequence
On Sep 13, 2007, at 8:19 AM, che wrote: Hi, Are there any database independent way to get the id from some sequence - for databases that supports it? For postgres this can be done by issueing select nextval('name_of_the_sequence') statement, but for other databases like oracle, firebird it is maybe different. It seems that there is no such protocol in SA source, but maybe i am missing something obvious. I assume that to distinguish the databases that support sequences metadata.bind.dialect.preexecute_sequences boolean can be used. am i right? regards, stefan p.s. currently i use the following code in postgres, but plan to use something in other databases too: sql = select nextval('\%s\') % name_of_the_sequence oid = db.connect().execute( sql.encode( db.dialect.encoding)).scalar() print oid id = connection.execute(Sequence('my_sequence')) --~--~-~--~~~---~--~~ 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] ClauseList as a column_property
Hello, Recently I started playing with SQLAlchemy. When implementing some database, I ran into this problem: The very neat column_property feature of SA accepts various constructs like comparisons, subselects and even other sql operators such as addition and concatenation. But boolean comparisons (represented by SA.sql.expression.ClauseList objects) cause the code to break, whilst in SQL these constructions are valid. The SQL query I'm trying to map is: SELECT id, begin_date, end_date, begin_date IS NOT NULL OR begin_date = NOW() AND end_date IS NULL OR end_date NOW() AS active FROM package WHERE active = 't' The SA version used is 0.4.0beta5 - from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite:///:memory:', echo=True) meta = MetaData(bind=engine) session = sessionmaker(bind=engine)() package_table = Table('package', meta, Column('id', Integer, primary_key=True), Column('begin_date', DateTime), Column('end_date', DateTime), ) meta.create_all() class Package(object): pass Here the column_property() is used in one of the documented ways. This works, but doesn't contain all of the logic for active packages: mapper(Package, package_table, properties={ 'active':column_property( (package_table.c.begin_date != None).label('active') ), }) Here is the active column with all logic defined, the code breaks as SA doesn't seem to allow logic comparisons within column_property(): clear_mappers() try: mapper(Package, package_table, properties={ 'active':column_property( (( (package_table.c.begin_date != None) | (package_table.c.begin_date = func.current_timestamp()) ) ( (package_table.c.end_date == None) | (package_table.c.end_date func.current_timestamp()) ) ).label('active')), }) except AttributeError, e: e contains: 'ClauseList' object has no attribute 'label' Or if we don't label the column_property construct: sqlalchemy.sql.expression.ClauseList object is not a valid candidate for ColumnProperty print e Playing around, I got to this solution. Which works like a charm. But the mapper code is not that clean anymore. clear_mappers() b = (package_table.c.begin_date == None) c = (( (package_table.c.begin_date != None) | (package_table.c.begin_date = func.current_timestamp()) ) ( (package_table.c.end_date == None) | (package_table.c.end_date func.current_timestamp()) )) ### Force the type c.type = b.type ### Which is a NoneType() ### Force the label from sqlalchemy.sql.expression import _Label labeled_c = _Label('active', c, c.type) s = select([package_table, labeled_c]).alias('package_select') mapper(Package, s) q = session.query(Package).filter_by(active=True) q.all() --- Can this be done in a less ugly way? If not currently, can SA be fixed so ClauseLists can be used within column_property? Aldough I tried, I couldn't write the patch on SA to fix it myself. Thanks a lot, Berik --~--~-~--~~~---~--~~ 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] Re: ClauseList as a column_property
On Sep 24, 2007, at 11:15 AM, Berik Visschers wrote: The SQL query I'm trying to map is: SELECT id, begin_date, end_date, begin_date IS NOT NULL OR begin_date = NOW() AND end_date IS NULL OR end_date NOW() AS active FROM package WHERE active = 't' more specifically youre looking for: SELECT id, begin_date, end_date, (begin_date IS NOT NULL OR begin_date = NOW() AND end_date IS NULL OR end_date NOW()) AS active FROM package WHERE active = 't' right ? I would think we can just add label() support to ClauseList for this. you can open a trac ticket for this and someone will get around to it, or if you want to try a patch (its not hard one). --~--~-~--~~~---~--~~ 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] Re: db independent way to get id from sequence
id = connection.execute(Sequence('my_sequence')) thanks, Michael --~--~-~--~~~---~--~~ 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] plain python objects from ORM
Hi, Is it possible to get SA ORM to return plain python objects (with eagerloaded relations and all) but without any attribute instrumentation (or anything else magically added by SA). Thanks, Huy --~--~-~--~~~---~--~~ 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] Re: r3507 breaks here
somethings weird. if i take out your expects/me.query stuff (which remains impossible to read), and do this : session.clear() for o in session.query(A): print str(o) I get this: C( db_id=1 linkA=None linkC=B( id=notset name=ben ) dataC=mc name=cc ) A( db_id=2 linkA=B( id=notset name=ben ) name=anna ) B( db_id=3 linkB=C( id=notset name=cc ) linkA=None name=ben dataB=gun ) which is correct. im trying all sorts of things and I cant get the linkB=B condition the test case claims. but this expects string: dict( klas= A, table= table_A, oid= a.db_id, exp_single= str(a), exp_multi = [ str(a), str(b), str(c) ]), returns the wrong result. what am i doing wrong ? On Sep 24, 2007, at 10:53 AM, [EMAIL PROTECTED] wrote: scratch that, i found one, try r3512. this one is ok now. Another one. - the A-B-C all-cases works 100% on 0.3.xx but some cases fail on 0.4.anything. Attached is one ~random case of about 168 similar ones - t1.py. ciao sa_gentestbase.py t1.py --~--~-~--~~~---~--~~ 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] Re: plain python objects from ORM
On Sep 24, 2007, at 11:48 AM, Huy Do wrote: Hi, Is it possible to get SA ORM to return plain python objects (with eagerloaded relations and all) but without any attribute instrumentation (or anything else magically added by SA). not really. unless you remove the instrumentation from the classes themselves afterwards (a one way operation). of course you could argue that theres no technical reason the ORM shouldnt be able to do this. there could be some extremely specialized rewrite of attributes.py that could do it perhaps, but maintaining test coverage for that would be a whole project in itself. --~--~-~--~~~---~--~~ 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] Re: r3507 breaks here
it something to do with that expects thing... just do a x = str(b) before session.clear(), breaks it all. On Monday 24 September 2007 18:57:36 Michael Bayer wrote: somethings weird. if i take out your expects/me.query stuff (which remains impossible to read), and do this : session.clear() for o in session.query(A): print str(o) I get this: C( db_id=1 linkA=None linkC=B( id=notset name=ben ) dataC=mc name=cc ) A( db_id=2 linkA=B( id=notset name=ben ) name=anna ) B( db_id=3 linkB=C( id=notset name=cc ) linkA=None name=ben dataB=gun ) which is correct. im trying all sorts of things and I cant get the linkB=B condition the test case claims. but this expects string: dict( klas= A, table= table_A, oid= a.db_id, exp_single= str(a), exp_multi = [ str(a), str(b), str(c) ]), returns the wrong result. what am i doing wrong ? On Sep 24, 2007, at 10:53 AM, [EMAIL PROTECTED] wrote: scratch that, i found one, try r3512. this one is ok now. Another one. - the A-B-C all-cases works 100% on 0.3.xx but some cases fail on 0.4.anything. Attached is one ~random case of about 168 similar ones - t1.py. ciao sa_gentestbase.py t1.py --~--~-~--~~~---~--~~ 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] Re: r3507 breaks here
On Sep 24, 2007, at 12:13 PM, [EMAIL PROTECTED] wrote: it something to do with that expects thing... just do a x = str(b) before session.clear(), breaks it all. OK...that was just a *great* way to spend all day tracking that one down. its fixed in 3515. I didn't bother to see why it doesn't exist in 0.3, but its confusing that it doesn't, since the basic mechanics of this one are present there as well, there must be some subtlety which conceals it. I hope you can find more insanely obscure bugs like this for me tomorrow ! --~--~-~--~~~---~--~~ 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] Re: r3507 breaks here
On Monday 24 September 2007 22:31:35 Michael Bayer wrote: On Sep 24, 2007, at 12:13 PM, [EMAIL PROTECTED] wrote: it something to do with that expects thing... just do a x = str(b) before session.clear(), breaks it all. OK...that was just a *great* way to spend all day tracking that one down. its fixed in 3515. I didn't bother to see why it doesn't exist in 0.3, but its confusing that it doesn't, since the basic mechanics of this one are present there as well, there must be some subtlety which conceals it. I hope you can find more insanely obscure bugs like this for me tomorrow ! at your service, sir |-: --~--~-~--~~~---~--~~ 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] Re: 0.4.0beta5 breaks [Oracle] query, works on 0.3.7 and with cxOracle
Here's another simple testcase that fails for Oracle beta5 but works with 0.3.7. It's about the simplest query I can come up with. Have a table with a date column in it and query against it using the to_date function. def test_to_date(): start_date = '10/05/04' where = cal_dim.c.adwkenddt == func.to_date(start_date,'MM/DD/RR') query = select([cal_dim.c.adwkenddt], whereclause=where ) result = query.execute() for r in result: print r This fails for beta5, works for .3.7. The error is:: Traceback (most recent call last): File s4.py, line 88, in ? test_to_date() File s4.py, line 59, in test_to_date result = query.execute() File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/sql/expression.py, line 973, in execute return compiled.execute(*multiparams, **params) File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 488, in execute return e._execute_compiled(self, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 1121, in _execute_compiled return connection._execute_compiled(compiled, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 832, in _execute_compiled self.__execute_raw(context) File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 850, in __execute_raw self._cursor_execute(context.cursor, context.statement, parameters, context=context) File /home/matt/work/vpython/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 867, in _cursor_execute raise exceptions.DBAPIError.instance(statement, parameters, e) sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-00932: inconsistent datatypes: expected NUMBER got CLOB 'SELECT AD_WEEK_CALENDAR_DIM.adwkenddt \nFROM AD_WEEK_CALENDAR_DIM \nWHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date(:to_date, :to_date_1)' {'to_date_1': 'MM/DD/RR', 'to_date': '10/05/04'} Am still confused as to the problem here I run the same query through text and it works:: def test_to_date_text(): s = text(SELECT AD_WEEK_CALENDAR_DIM.adwkenddt FROM AD_WEEK_CALENDAR_DIM WHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date(:to_date, :to_date_1)) result = connection.execute(s, to_date_1= 'MM/DD/RR', to_date= '10/05/04') for r in result: print r --~--~-~--~~~---~--~~ 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] Re: 0.4.0beta5 breaks [Oracle] query, works on 0.3.7 and with cxOracle
sorry, i havent forgotten you. just have to get the time to power up my oracle box. thanks for putting in the ticket. On Sep 24, 2007, at 7:22 PM, m h wrote: Here's another simple testcase that fails for Oracle beta5 but works with 0.3.7. It's about the simplest query I can come up with. Have a table with a date column in it and query against it using the to_date function. def test_to_date(): start_date = '10/05/04' where = cal_dim.c.adwkenddt == func.to_date(start_date,'MM/DD/RR') query = select([cal_dim.c.adwkenddt], whereclause=where ) result = query.execute() for r in result: print r This fails for beta5, works for .3.7. The error is:: Traceback (most recent call last): File s4.py, line 88, in ? test_to_date() File s4.py, line 59, in test_to_date result = query.execute() File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/sql/expression.py, line 973, in execute return compiled.execute(*multiparams, **params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 488, in execute return e._execute_compiled(self, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 1121, in _execute_compiled return connection._execute_compiled(compiled, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 832, in _execute_compiled self.__execute_raw(context) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 850, in __execute_raw self._cursor_execute(context.cursor, context.statement, parameters, context=context) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 867, in _cursor_execute raise exceptions.DBAPIError.instance(statement, parameters, e) sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-00932: inconsistent datatypes: expected NUMBER got CLOB 'SELECT AD_WEEK_CALENDAR_DIM.adwkenddt \nFROM AD_WEEK_CALENDAR_DIM \nWHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date(:to_date, :to_date_1)' {'to_date_1': 'MM/DD/RR', 'to_date': '10/05/04'} Am still confused as to the problem here I run the same query through text and it works:: def test_to_date_text(): s = text(SELECT AD_WEEK_CALENDAR_DIM.adwkenddt FROM AD_WEEK_CALENDAR_DIM WHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date (:to_date, :to_date_1)) result = connection.execute(s, to_date_1= 'MM/DD/RR', to_date= '10/05/04') for r in result: print r --~--~-~--~~~---~--~~ 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] best practices for catching sqlerrors
In my application I'd like db related errors that are encountered when using mapped classes to have better exceptions that make more sense in the context of my program. Where is the best place to put this stuff? For example, say I have a table with a single primary_key column and I have a class MyData mapped to that table. If someone were to try to make and flush a MyData(someDuplicateEntry) instance they'd get an ugly sqlalchemy exception. I'd rather they get, say, an AlreadyExistsException() or something to that effect. Now, I can wrap each flush with a try/except block, or have the __init__ method of the class do a check during instantiation, but I'm wondering if there is some better way to do it. Perhaps a way to map SqlerrorA to throw ExceptionA and SqlerrorB to throw ExceptionB. Thanks, Ron --~--~-~--~~~---~--~~ 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] Re: plain python objects from ORM
Michael Bayer wrote: On Sep 24, 2007, at 11:48 AM, Huy Do wrote: Hi, Is it possible to get SA ORM to return plain python objects (with eagerloaded relations and all) but without any attribute instrumentation (or anything else magically added by SA). not really. unless you remove the instrumentation from the classes themselves afterwards (a one way operation). Any pointers on how to do this ? to the whole object hierachy. of course you could argue that theres no technical reason the ORM shouldnt be able to do this. there could be some extremely specialized rewrite of attributes.py that could do it perhaps, but maintaining test coverage for that would be a whole project in itself Would a mapper extension allow me to do this ? I think this would be a great feature to have because there are many use cases in my application (mainly displaying/processing tables) where I don't want/need the overhead of the instrumentation (and it really does add quite a bit), but would still love the excellent mapping abilities (i.e have fully hydrated domain objects rather then ResultProxy). Thanks Huy --~--~-~--~~~---~--~~ 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] Re: 0.4.0beta5 breaks [Oracle] query, works on 0.3.7 and with cxOracle
NP, I know Oracle is a drag but that's what the client has. Perhaps if you could clarify why I'm confused I might be able to help debug. (I've stepped through expression.py all day long). I feel like I just need a little hint or push in the right direction. Eventually you get to a cx cursor and call execute with the statement on it. How does the same statement/parameter combo fail with SQL generate, yet succeed using `text` or plain cx? If I can get over that hump, I think I might be able to give you a patch. On 9/24/07, Michael Bayer [EMAIL PROTECTED] wrote: sorry, i havent forgotten you. just have to get the time to power up my oracle box. thanks for putting in the ticket. On Sep 24, 2007, at 7:22 PM, m h wrote: Here's another simple testcase that fails for Oracle beta5 but works with 0.3.7. It's about the simplest query I can come up with. Have a table with a date column in it and query against it using the to_date function. def test_to_date(): start_date = '10/05/04' where = cal_dim.c.adwkenddt == func.to_date(start_date,'MM/DD/RR') query = select([cal_dim.c.adwkenddt], whereclause=where ) result = query.execute() for r in result: print r This fails for beta5, works for .3.7. The error is:: Traceback (most recent call last): File s4.py, line 88, in ? test_to_date() File s4.py, line 59, in test_to_date result = query.execute() File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/sql/expression.py, line 973, in execute return compiled.execute(*multiparams, **params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 488, in execute return e._execute_compiled(self, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 1121, in _execute_compiled return connection._execute_compiled(compiled, multiparams, params) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 832, in _execute_compiled self.__execute_raw(context) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 850, in __execute_raw self._cursor_execute(context.cursor, context.statement, parameters, context=context) File /home/matt/work/vpython/lib/python2.4/site-packages/ SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/engine/base.py, line 867, in _cursor_execute raise exceptions.DBAPIError.instance(statement, parameters, e) sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-00932: inconsistent datatypes: expected NUMBER got CLOB 'SELECT AD_WEEK_CALENDAR_DIM.adwkenddt \nFROM AD_WEEK_CALENDAR_DIM \nWHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date(:to_date, :to_date_1)' {'to_date_1': 'MM/DD/RR', 'to_date': '10/05/04'} Am still confused as to the problem here I run the same query through text and it works:: def test_to_date_text(): s = text(SELECT AD_WEEK_CALENDAR_DIM.adwkenddt FROM AD_WEEK_CALENDAR_DIM WHERE AD_WEEK_CALENDAR_DIM.adwkenddt = to_date (:to_date, :to_date_1)) result = connection.execute(s, to_date_1= 'MM/DD/RR', to_date= '10/05/04') for r in result: print r --~--~-~--~~~---~--~~ 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] Re: plain python objects from ORM
On Tuesday 25 September 2007 05:43:40 Huy Do wrote: Michael Bayer wrote: On Sep 24, 2007, at 11:48 AM, Huy Do wrote: Hi, Is it possible to get SA ORM to return plain python objects (with eagerloaded relations and all) but without any attribute instrumentation (or anything else magically added by SA). not really. unless you remove the instrumentation from the classes themselves afterwards (a one way operation). Any pointers on how to do this ? to the whole object hierachy. just grab the objects __dict__, and make any class out of it. u'll need 2 parralel class hierarchies, or maybe one parasit hierarhcy hanging on the other.. e.g. class Aplain: methods... def undress(self): r = self.__class__(); r.__dict__.update( self.__dict__); return r class Aplain4SA(Aplain): pass m = mapper( Aplain4SA, ...) ... def myquery( query): for q in query: yield q.undress() and use myquery() as wrapper for all session.query(..) the overhead would be one generator.. --~--~-~--~~~---~--~~ 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] Re: r3507 breaks here
On Monday 24 September 2007 22:31:35 Michael Bayer wrote: On Sep 24, 2007, at 12:13 PM, [EMAIL PROTECTED] wrote: it something to do with that expects thing... just do a x = str(b) before session.clear(), breaks it all. OK...that was just a *great* way to spend all day tracking that one down. its fixed in 3515. I didn't bother to see why it doesn't exist in 0.3, but its confusing that it doesn't, since the basic mechanics of this one are present there as well, there must be some subtlety which conceals it. I hope you can find more insanely obscure bugs like this for me tomorrow ! now that u mentioned it... r3515 introduces something: File /home/az/src/dbcook/sqlalchemy/orm/query.py, line 619, in __iter__ return self._execute_and_instances(statement) File /home/az/src/dbcook/sqlalchemy/orm/query.py, line 624, in _execute_and_instances return iter(self.instances(result)) File /home/az/src/dbcook/sqlalchemy/orm/query.py, line 680, in instances self.select_mapper._instance(context, row, result) File /home/az/src/dbcook/sqlalchemy/orm/mapper.py, line 1360, in _instance discriminator = row[self.polymorphic_on] File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1590, in __getitem__ return self.__parent._get_col(self.__row, key) File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1394, in _get_col rec = self._key_cache[key] File /home/az/src/dbcook/sqlalchemy/util.py, line 72, in __missing__ self[key] = val = self.creator(key) File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1304, in lookup_key raise exceptions.NoSuchColumnError(Could not locate column in row for column '%s' % (str(key))) NoSuchColumnError: Could not locate column in row for column 'pu_a.atype' ? failed A.query_SUB_instances: Could not locate column in row for column 'pu_a.atype' pu_a is polymorphic union, and fails only if from_statement() is involved. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- _t3515.py Description: application/python sa_gentestbase.py Description: application/python