[sqlalchemy] Re: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Hello Michael, Thanks for your input! I got the latest trunk from SVN. However, if my app specific baseclass is an old style class, it still breaks., this time in orm\attributes.py Traceback (most recent call last): File SqlDB_Test.py, line 9, in ? dbo = SqlDB(SqlDB_Test.Sqlite,c:\\testdbs) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 77, in __init_ _ self.initSetup(echo) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 115, in initSe tup elixir.setup_all(True) File d:\recogsys\src\python\rsiterm\__init__.py, line 145, in setup_all File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\__init__.py, line 643, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 197, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 852, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1494, in create_manager_for_cls manager = factory(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1047, in __init__ cls_state = manager_of_class(base) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1511, in manager_of_class finder = self.manager_finders[cls] File C:\Python24\lib\weakref.py, line 219, in __getitem__ return self.data[ref(key)] TypeError: cannot create weak reference to 'classobj' object This error goes away when I make my app baseclass as a new style class. It is not giving any problems with Exceptions class in Py2.4 though. Could this be a possible issue? On Wed, Aug 20, 2008 at 9:28 PM, Michael Bayer [EMAIL PROTECTED]wrote: On Aug 20, 2008, at 11:52 AM, Harish K Vishwanath wrote: Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? no worries...use the latest trunk, which will ultimately be released either as 0.5beta4 or 0.5.0. -- Regards, Harish --~--~-~--~~~---~--~~ 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: Non UTF8 strings retreived via mapped class - 0.5beta3
It looks pretty clear that this is a Django error. It's calling str(s) which will fail for a unicode object which contains multibyte characters, which would be the case for a UTF-8 encoded string converted to unicode by SQLAlchemy.. It clearly isn't a Django error! Python Shell: Source.metadata.create_all(engine) results = session.query(Source).all() results Gives the same errors. I think SQLAlchemy is returning non UTF8 strings here. This happens in a python shell, an IPython shell (with no Django anywhere). I'm off to try a different version. Will --~--~-~--~~~---~--~~ 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] Could there be a behavioural difference in user defined DataTypes?
Hello, I have a class defining our own data type : class RsiSqliteDateTimeType(types.TypeEngine): def __init__(self): pass def get_col_spec(self): return VARCHAR(35) def convert_bind_param(self, value, engine): if value != None: return value.ToString() return None def convert_result_value(self, value, engine): if value != None: return dtime.CIRDateTime(value) return None CIRDateTime() is a custom written DateTime class. Now, a few of my test cases which would pass thru SQLA 0.4.6 is failing in SQLA 0.5beta4dev (latest trunk). It basically involves a lesser than comparision between CIRDateTime() object picked from SQLite database vs a newly passed CIRDateTime() object. in SQLA 0.4.6 : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp True in SQLA 0.5beta4 latest trunk : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp False I am still trying to find out why this anomaly is occuring. I went through the 0.5 migration guide, which talks about changes in the way milliseconds are stored on SQLITE, but this is my user defined data type. Could there be any difference between the two versions? -- Regards, Harish --~--~-~--~~~---~--~~ 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: problem with ExtensionMapper
Ok, so the problem might be because the first test fails while doing Session.clear(): Traceback (most recent call last): File .../tests/__init__.py, line 35, in tearDown Session.clear() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/scoping.py, line 98, in do return getattr(self.registry(), name)(*args, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 668, in clear self._unattach(instance) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 1141, in _unattach if instance._sa_session_id == self.hash_key: AttributeError: 'User' object has no attribute '_sa_session_id' The background for this situation is in the first post of this thread: create_instance simply returns User() object. However, if instead of that I return EXT_CONTINUE - everything works fine. So maybe there's something missing in my create_instance definition? On 4 Rugp, 18:11, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 4, 2008, at 4:29 AM, naktinis wrote: User.__init__() only contains attribute assignments like: def __init__(self, **kw): self.name = kw.get('name', u'') ... self.email = kw.get('email', u'') Nothing more. What details would be more helpful? something else is going on. you'd have to provide us with a complete test case which reproduces the issue. On 2 Rugp, 20:35, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 2, 7:46 am, naktinis [EMAIL PROTECTED] wrote: Hi, I have created an ExtensionMapper: class UserMapperExtension(MapperExtension): defcreate_instance(self, mapper, selectcontext, row, class_): return User() Session.mapper(User, user_table, extension=UserMapperExtension()) At first everything seemed to work fine, but when I runned my unit tests (nosetests) I get errors (if I turn off the extension they are gone). After every: super(UserTestCase, self).setUp() Session.flush() I get: ConcurrentModificationError: Updated rowcount 0 does not match number of objects updated 1 Or sometimes: IntegrityError: (IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails ... CONSTRAINT 'some_constraint' FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))') u'UPDATE other SET user_id=%s WHERE other.id = %s' which were not present before adding the ExtensionMapper. What could be the problem? what kind of behavior fires off in User.__init__() ? other than that you'd have to provide a more concrete 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: declarative
On Tue, 2008-08-19 at 16:16 -0400, Michael Bayer wrote: On Aug 19, 2008, at 4:07 PM, Gaetan de Menten wrote: Simpler than Elixir? How so? If you are speaking about the internal guts, then you are right declarative is simpler (which is normal since it does less), but if you meant the usage (and I *think* it's what the original poster meant here), I have to disagree... Their simplicity is comparable, and I would even vote for Elixir as slightly simpler because of the little helper methods you get for free... If you meant usage here, please explain why you think so. As far as declarative being simpler I would say, source code wise, architecture wise, things-that-can-go-wrong-wise (i.e., an configurational error message in Elixir can be an elixir problem, or a SQLA problem, or both, its hard to trace), as well as that you only have to learn one paradigm, not two, in order to use it. Though on the last point perhaps Elixir is finally getting to the point where you really don't need to know SQLA configuration in order to use it. Just another datapoint: me too. I started out with elixir but soon switched to declarative because too many times I shot myself in the foot with the subtle differences/interactions between elixir and SA. Furthermore pretty much all SA documentation you can find is in pure SA-speak. I found it easier to convert that to declarative-speak than to elixir-speak because declarative is closer to the real thing. IMHO elixir is a two-bladed sword. If you know that your task at hand is very simple (and will stay that way) then it can help you with the syntactic sugar. Everyone else will eventually grow out of it. regards -jj --~--~-~--~~~---~--~~ 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] Cascading delete
Hi there, I spoke with zzzeek_ on IRC yesterday re: some code I'd written for an introspective cascading delete function. We were previously using the ORM to do this for us but, due to the way it works, it was taking several minutes to delete large amounts of second-generation orphans. The code I've written recursively gets all the tables involved, analyses the relationships and issues as few delete statements as possible (I hope). I've attached the code, or there's a link to it here: http://paste.pocoo.org/show/82878/ With parent-child relationships my tests are showing this working much, much faster than the ORM (by a factor of at least 100x). I haven't had a chance to set up more complicated tables to fully test the recursive aspect of it but it has worked with what I've given it so far. I'm really enjoying working with SQLAlchemy, you guys have done a really good job. If you think there's room for something like this in SA then it's all yours. :-) Cheers, -- -- Bob Farrell pH, an Experian Company www.phgroup.com Office Line: 020 7598 0310 Fax: 020 7598 0311 -- --~--~-~--~~~---~--~~ 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 class_mapper, select from sqlalchemy.sql import delete def delete_cascade(orm_obj): Perform a cascading delete on any ORM object and its children. # Since we take an ORM _object_, we need to discover its table: obj_table = class_mapper(type(orm_obj)).mapped_table def get_child_tables(parent_table, children=[]): Recursively find all child tables. new_children = [] # Use SQLAlchemy's table_iterator reversed to give us the tables in the # correct order to ensure that we can delete without breaking any constraints # (i.e. we will not delete a parent before its child: for table in obj_table.metadata.table_iterator(reverse=True): for fk in table.foreign_keys: if fk.references(parent_table) and \ (table, fk, parent_table) not in children: new_children.append((table, fk, parent_table)) break # If no new children are found we have reached the top of the recursion so we # fall back down the stack: if not new_children: return [] else: for child in new_children: # Here is the recursive call: children.extend(get_child_tables(child[0])) children.extend(new_children) return children _children = get_child_tables(obj_table) children = [] # This loop filters out any tables who have more than one foreign key where one # of the foreign keys references the root node so we have no duplicates. The # result is a list of tables that reference either the root node or their # parent: for child in _children: if child[0] not in [x[0] for x in children]: children.append(child) elif child[1].references(obj_table): for i, _child in enumerate(children): if _child[0] == child[0]: children[i] = child break # This is a rare-case optimisation that sees if any of the tables reference the # root node indirectly by having a foreign key whose counterpart is a direct # reference to the root node: for child in children: table, fk, parent_table = child if not fk.references(obj_table): parent_fk = fk.column.foreign_key while parent_fk is not None: if parent_fk.references(obj_table): obj_column = ( parent_fk.column.key ) break parent_fk = parent_fk.column.foreign_key # Finally build a select for grandchildren or later to establish which records # need to be removed by seeing which of their parent's records are ancestors of # the root node: if parent_fk is None: sel = select([fk.parent]) parent_fk = fk.column.foreign_key while parent_fk is not None: sel.append_whereclause( parent_fk.parent==parent_fk.column ) tmp = parent_fk.column.foreign_key if tmp is not None: parent_fk = tmp else: break obj_column = ( parent_fk.column.key ) sel.append_whereclause( parent_fk.column==getattr(orm_obj, obj_column) )
[sqlalchemy] composites
hi i plan to implement embedded structures in dbcook (as opposed to referenced structures living in separate tables), and composite props seems to fit nicely. the idea is to achieve something like: class Point( embeddableBase): x = Int() y = Int() class Vertex( base): p1 = Point() p2 = Point() which should create a table/mapping with columns ( p1_x, p1_y, p2_x, p2_y ) and a mapper with the p1, p2 as composite_props. the plain columns are still accessible via the mapper, right? e.g. query(Vertex).filter( Vertex.p1_x 4 ) can composite's props be used in query expressions? e.g. query(Vertex).filter( Vertex.p1.x 4 ) can composite's props be assigned separately ? e.g. would this work? v = Vertex( ...) v.p1.x = 3 v.p2 = Point( 1,2) v.p1_y = 5 ciao 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: Cascading delete
Hi Bob Looks like you're doing some fun thinking :) Steve On Thu, Aug 21, 2008 at 11:04 AM, Bob Farrell [EMAIL PROTECTED] wrote: Hi there, I spoke with zzzeek_ on IRC yesterday re: some code I'd written for an introspective cascading delete function. We were previously using the ORM to do this for us but, due to the way it works, it was taking several minutes to delete large amounts of second-generation orphans. The code I've written recursively gets all the tables involved, analyses the relationships and issues as few delete statements as possible (I hope). I've attached the code, or there's a link to it here: http://paste.pocoo.org/show/82878/ With parent-child relationships my tests are showing this working much, much faster than the ORM (by a factor of at least 100x). I haven't had a chance to set up more complicated tables to fully test the recursive aspect of it but it has worked with what I've given it so far. I'm really enjoying working with SQLAlchemy, you guys have done a really good job. If you think there's room for something like this in SA then it's all yours. :-) Cheers, -- -- Bob Farrell pH, an Experian Company www.phgroup.com Office Line: 020 7598 0310 Fax: 020 7598 0311 -- --~--~-~--~~~---~--~~ 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] Listening append() and remove()
Hi all! I'm looking for an easy way to get informed when someone append or remove an object from a specific one-to-many relation. For example to keep a count on the parent object, with no need to query the children. There are a lot of stuff about it, but I'm not sure how to do it really: - 1st : http://markmail.org/message/oyt57qx3247jdhgi#query:sqlalchemy%20__sa_instrument_class__+page:1+mid:wz4wkumhvnnm74yw+state:results Does not seem to work on 0.5 - 2nd : CollectionAdapter.append_with_event method let me think there is a way to register a callback somewhere, but where? - 3rd : class MyInstrumentedList(list) with appropriate decorated methods like @collection.appender. But does it work when a 'clear' is called? Did I miss something? Thanks a lot! Gus --~--~-~--~~~---~--~~ 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: declarative
On Thu, Aug 21, 2008 at 2:06 PM, Jim Jones [EMAIL PROTECTED] wrote: On Tue, 2008-08-19 at 16:16 -0400, Michael Bayer wrote: On Aug 19, 2008, at 4:07 PM, Gaetan de Menten wrote: Simpler than Elixir? How so? If you are speaking about the internal guts, then you are right declarative is simpler (which is normal since it does less), but if you meant the usage (and I *think* it's what the original poster meant here), I have to disagree... Their simplicity is comparable, and I would even vote for Elixir as slightly simpler because of the little helper methods you get for free... If you meant usage here, please explain why you think so. As far as declarative being simpler I would say, source code wise, architecture wise, things-that-can-go-wrong-wise (i.e., an configurational error message in Elixir can be an elixir problem, or a SQLA problem, or both, its hard to trace), as well as that you only have to learn one paradigm, not two, in order to use it. Though on the last point perhaps Elixir is finally getting to the point where you really don't need to know SQLA configuration in order to use it. Just another datapoint: me too. I started out with elixir but soon switched to declarative because too many times I shot myself in the foot with the subtle differences/interactions between elixir and SA. Furthermore pretty much all SA documentation you can find is in pure SA-speak. I found it easier to convert that to declarative-speak than to elixir-speak because declarative is closer to the real thing. That's true... to some extent. Once you get that all arguments to relation can be also passed to the different Elixir relationships, and column arguments passed to Field, translating SA-speak to Elixir-speak becomes trivial. IMHO elixir is a two-bladed sword. If you know that your task at hand is very simple (and will stay that way) then it can help you with the syntactic sugar. These days, Elixir can handle almost any situation that SA can handle. The only limitation that will never be overcome by Elixir, (but neither by declarative) is to be able to map one class several times (to different selectables). Everyone else will eventually grow out of it. That's quite a bold claim... Ok, Elixir is not your style, that's fine. Also, Elixir certainly doesn't suit every project out there, I'm aware of that. But implying it's not worth it for anybody is well... uninformed. Just don't bash something you probably don't really know. -- Gaëtan de Menten http://openhex.org --~--~-~--~~~---~--~~ 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: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Thanks for the traceback. Give r5050 a try. Cheers, Jason Harish K Vishwanath wrote: Hello Michael, Thanks for your input! I got the latest trunk from SVN. However, if my app specific baseclass is an old style class, it still breaks., this time in orm\attributes.py Traceback (most recent call last): File SqlDB_Test.py, line 9, in ? dbo = SqlDB(SqlDB_Test.Sqlite,c:\\testdbs) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 77, in __init_ _ self.initSetup(echo) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 115, in initSe tup elixir.setup_all(True) File d:\recogsys\src\python\rsiterm\__init__.py, line 145, in setup_all File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\__init__.py, line 643, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 197, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 852, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1494, in create_manager_for_cls manager = factory(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1047, in __init__ cls_state = manager_of_class(base) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1511, in manager_of_class finder = self.manager_finders[cls] File C:\Python24\lib\weakref.py, line 219, in __getitem__ return self.data[ref(key)] TypeError: cannot create weak reference to 'classobj' object This error goes away when I make my app baseclass as a new style class. It is not giving any problems with Exceptions class in Py2.4 though. Could this be a possible issue? On Wed, Aug 20, 2008 at 9:28 PM, Michael Bayer [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: On Aug 20, 2008, at 11:52 AM, Harish K Vishwanath wrote: Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? no worries...use the latest trunk, which will ultimately be released either as 0.5beta4 or 0.5.0. http://0.5.0. -- Regards, Harish --~--~-~--~~~---~--~~ 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: Non UTF8 strings retreived via mapped class - 0.5beta3
On Aug 21, 2008, at 5:02 AM, William Temperley wrote: It looks pretty clear that this is a Django error. It's calling str(s) which will fail for a unicode object which contains multibyte characters, which would be the case for a UTF-8 encoded string converted to unicode by SQLAlchemy.. It clearly isn't a Django error! Python Shell: Source.metadata.create_all(engine) results = session.query(Source).all() results Gives the same errors. I think SQLAlchemy is returning non UTF8 strings here. This happens in a python shell, an IPython shell (with no Django anywhere). one thing to note is that SQLA has no capability to return a non- UTF8 string. It either returns the string data as received from the database, with whatever encoding that string happens to be in, or it returns a python unicode object. It's the latter case that calling str() on an attribute will fail, if the unicode object contains characters which are not representable in ASCII. --~--~-~--~~~---~--~~ 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: Could there be a behavioural difference in user defined DataTypes?
On Aug 21, 2008, at 5:07 AM, Harish K Vishwanath wrote: Hello, I have a class defining our own data type : class RsiSqliteDateTimeType(types.TypeEngine): def __init__(self): pass def get_col_spec(self): return VARCHAR(35) def convert_bind_param(self, value, engine): if value != None: return value.ToString() return None def convert_result_value(self, value, engine): if value != None: return dtime.CIRDateTime(value) return None CIRDateTime() is a custom written DateTime class. Now, a few of my test cases which would pass thru SQLA 0.4.6 is failing in SQLA 0.5beta4dev (latest trunk). It basically involves a lesser than comparision between CIRDateTime() object picked from SQLite database vs a newly passed CIRDateTime() object. in SQLA 0.4.6 : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp True in SQLA 0.5beta4 latest trunk : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp False I am still trying to find out why this anomaly is occuring. I went through the 0.5 migration guide, which talks about changes in the way milliseconds are stored on SQLITE, but this is my user defined data type. Could there be any difference between the two versions? there's no difference in behavior at the level you describe. If SQLA's DateTime object is not in use within your application, then the changes to that object from 0.4 to 0.5 will not impact the behavior of your app. --~--~-~--~~~---~--~~ 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: problem with ExtensionMapper
On Aug 21, 2008, at 7:02 AM, naktinis wrote: Ok, so the problem might be because the first test fails while doing Session.clear(): Traceback (most recent call last): File .../tests/__init__.py, line 35, in tearDown Session.clear() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/scoping.py, line 98, in do return getattr(self.registry(), name)(*args, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 668, in clear self._unattach(instance) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 1141, in _unattach if instance._sa_session_id == self.hash_key: AttributeError: 'User' object has no attribute '_sa_session_id' The background for this situation is in the first post of this thread: create_instance simply returns User() object. However, if instead of that I return EXT_CONTINUE - everything works fine. So maybe there's something missing in my create_instance definition? There should be nothing needed within the create_instance() definition, and _sa_session_id is set on all instances unconditionally within create_instance(). You'll have to provide a complete example of usage here. --~--~-~--~~~---~--~~ 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: Listening append() and remove()
On Aug 21, 2008, at 9:19 AM, GustaV wrote: Hi all! I'm looking for an easy way to get informed when someone append or remove an object from a specific one-to-many relation. For example to keep a count on the parent object, with no need to query the children. There are a lot of stuff about it, but I'm not sure how to do it really: - 1st : http://markmail.org/message/oyt57qx3247jdhgi#query:sqlalchemy %20__sa_instrument_class__+page:1+mid:wz4wkumhvnnm74yw+state:results Does not seem to work on 0.5 this is the correct approach. The names have changed per examples/ custom_attributes/custom_management.py . from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.orm.interfaces import AttributeExtension class ReceiveEvents(AttributeExtension): def append(self, obj, child, initiator): print append, obj, child def remove(self, obj, child, initiator): print remove, obj, child def set(self, obj, child, oldchild, initiator): print set, obj, child listener = ReceiveEvents() class SetListener(InstrumentationManager): def instrument_attribute(self, class_, key, inst): inst.impl.extensions.append(listener) if __name__ == '__main__': m = MetaData() t = Table('t', m, Column('a', Integer, primary_key=True), Column('b', String)) class C(object): __sa_instrumentation_manager__ = SetListener mapper(C, t) c1 = C() c1.a = 4 c1.b = test --~--~-~--~~~---~--~~ 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: problem with ExtensionMapper
On Aug 21, 2008, at 10:45 AM, Michael Bayer wrote: On Aug 21, 2008, at 7:02 AM, naktinis wrote: Ok, so the problem might be because the first test fails while doing Session.clear(): Traceback (most recent call last): File .../tests/__init__.py, line 35, in tearDown Session.clear() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/scoping.py, line 98, in do return getattr(self.registry(), name)(*args, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 668, in clear self._unattach(instance) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/ sqlalchemy/orm/session.py, line 1141, in _unattach if instance._sa_session_id == self.hash_key: AttributeError: 'User' object has no attribute '_sa_session_id' The background for this situation is in the first post of this thread: create_instance simply returns User() object. However, if instead of that I return EXT_CONTINUE - everything works fine. So maybe there's something missing in my create_instance definition? There should be nothing needed within the create_instance() definition, and _sa_session_id is set on all instances unconditionally within create_instance(). You'll have to provide a complete example of usage here. correction, I meant to say, _sa_session_id is set unconditionally within Mapper._instance(), after create_instance() has been called if at all. --~--~-~--~~~---~--~~ 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: composites
On Thursday 21 August 2008 17:57:31 Michael Bayer wrote: On Aug 21, 2008, at 9:03 AM, [EMAIL PROTECTED] wrote: hi i plan to implement embedded structures in dbcook (as opposed to referenced structures living in separate tables), and composite props seems to fit nicely. the idea is to achieve something like: class Point( embeddableBase): x = Int() y = Int() class Vertex( base): p1 = Point() p2 = Point() which should create a table/mapping with columns ( p1_x, p1_y, p2_x, p2_y ) and a mapper with the p1, p2 as composite_props. the plain columns are still accessible via the mapper, right? e.g. query(Vertex).filter( Vertex.p1_x 4 ) can composite's props be used in query expressions? e.g. query(Vertex).filter( Vertex.p1.x 4 ) Not by default, the composite attribute p1 and p2 would prevent p1_x, p1_y, etc. from being mapped. you could try explicitly mapping them, i havent experimented much with that. it becomes a gray area since which attribute would it favor for the ultimate value to be persisted? plain descriptors look like a better solution here (composites are probably an unnecessary feature in the first place). can composite's props be assigned separately ? e.g. would this work? v = Vertex( ...) v.p1.x = 3 v.p2 = Point( 1,2) v.p1_y = 5 yeah that wont work at all. With a descriptor based approach (and a Point object that knows how to proxy to the parent object), it could. ahha. i was thiking that composites _are_ just a sort of bridge to the attributes under it. Then, if i put proper descriptor, can i hook some PropComparator on it? so i can do the query(Vertex).filter( Vertex.p1 == Point(2,1) ) --~--~-~--~~~---~--~~ 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: composites
Mike, a question related to you saying composites aren't a necessary feature in the first place. Would it be possible using just Python properties and synonym() to do something similar to the composites example in the doc, namely query(Vertex).filter(Vertex.start == Point(3, 4))? Thanks. Eric 2008/8/21, Michael Bayer [EMAIL PROTECTED]: On Aug 21, 2008, at 9:03 AM, [EMAIL PROTECTED] wrote: hi i plan to implement embedded structures in dbcook (as opposed to referenced structures living in separate tables), and composite props seems to fit nicely. the idea is to achieve something like: class Point( embeddableBase): x = Int() y = Int() class Vertex( base): p1 = Point() p2 = Point() which should create a table/mapping with columns ( p1_x, p1_y, p2_x, p2_y ) and a mapper with the p1, p2 as composite_props. the plain columns are still accessible via the mapper, right? e.g. query(Vertex).filter( Vertex.p1_x 4 ) can composite's props be used in query expressions? e.g. query(Vertex).filter( Vertex.p1.x 4 ) Not by default, the composite attribute p1 and p2 would prevent p1_x, p1_y, etc. from being mapped. you could try explicitly mapping them, i havent experimented much with that. it becomes a gray area since which attribute would it favor for the ultimate value to be persisted? plain descriptors look like a better solution here (composites are probably an unnecessary feature in the first place). can composite's props be assigned separately ? e.g. would this work? v = Vertex( ...) v.p1.x = 3 v.p2 = Point( 1,2) v.p1_y = 5 yeah that wont work at all. With a descriptor based approach (and a Point object that knows how to proxy to the parent object), it could. --~--~-~--~~~---~--~~ 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: composites
Just realized that my question is similar to az's :) Eric 2008/8/21, Eric Lemoine [EMAIL PROTECTED]: Mike, a question related to you saying composites aren't a necessary feature in the first place. Would it be possible using just Python properties and synonym() to do something similar to the composites example in the doc, namely query(Vertex).filter(Vertex.start == Point(3, 4))? Thanks. Eric 2008/8/21, Michael Bayer [EMAIL PROTECTED]: On Aug 21, 2008, at 9:03 AM, [EMAIL PROTECTED] wrote: hi i plan to implement embedded structures in dbcook (as opposed to referenced structures living in separate tables), and composite props seems to fit nicely. the idea is to achieve something like: class Point( embeddableBase): x = Int() y = Int() class Vertex( base): p1 = Point() p2 = Point() which should create a table/mapping with columns ( p1_x, p1_y, p2_x, p2_y ) and a mapper with the p1, p2 as composite_props. the plain columns are still accessible via the mapper, right? e.g. query(Vertex).filter( Vertex.p1_x 4 ) can composite's props be used in query expressions? e.g. query(Vertex).filter( Vertex.p1.x 4 ) Not by default, the composite attribute p1 and p2 would prevent p1_x, p1_y, etc. from being mapped. you could try explicitly mapping them, i havent experimented much with that. it becomes a gray area since which attribute would it favor for the ultimate value to be persisted? plain descriptors look like a better solution here (composites are probably an unnecessary feature in the first place). can composite's props be assigned separately ? e.g. would this work? v = Vertex( ...) v.p1.x = 3 v.p2 = Point( 1,2) v.p1_y = 5 yeah that wont work at all. With a descriptor based approach (and a Point object that knows how to proxy to the parent object), it could. --~--~-~--~~~---~--~~ 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: composites
On Thursday 21 August 2008 17:57:31 Michael Bayer wrote: On Aug 21, 2008, at 9:03 AM, [EMAIL PROTECTED] wrote: hi i plan to implement embedded structures in dbcook (as opposed to referenced structures living in separate tables), and composite props seems to fit nicely. the idea is to achieve something like: class Point( embeddableBase): x = Int() y = Int() class Vertex( base): p1 = Point() p2 = Point() which should create a table/mapping with columns ( p1_x, p1_y, p2_x, p2_y ) and a mapper with the p1, p2 as composite_props. the plain columns are still accessible via the mapper, right? e.g. query(Vertex).filter( Vertex.p1_x 4 ) can composite's props be used in query expressions? e.g. query(Vertex).filter( Vertex.p1.x 4 ) Not by default, the composite attribute p1 and p2 would prevent p1_x, p1_y, etc. from being mapped. you could try explicitly mapping them, i havent experimented much with that. it becomes a gray area since which attribute would it favor for the ultimate value to be persisted? plain descriptors look like a better solution here (composites are probably an unnecessary feature in the first place). can composite's props be assigned separately ? e.g. would this work? v = Vertex( ...) v.p1.x = 3 v.p2 = Point( 1,2) v.p1_y = 5 yeah that wont work at all. With a descriptor based approach (and a Point object that knows how to proxy to the parent object), it could. no worries, here a simulation of what can be done under the dbcook' hood: class composer( object): class proxy( object): __slots__ = 'obj name'.split() @staticmethod def make_name( name, subname): return name + '_' + subname def __init__( me, obj, name): me.obj = obj me.name = name def __getattr__( me, key): return getattr( me.obj, me.make_name( me.name, key)) def __setattr__( me, key, val): if key in me.__slots__: return object.__setattr__( me, key, val) return setattr( me.obj, me.make_name( me.name, key), val) def __init__( me, name): me.name = name def __get__( me, obj, klas ): return me.proxy( obj or klas, me.name) class Vertex( Base): a_x = Int() a_y = Int() a = composer( 'a') b_x = Int() b_y = Int() b = composer( 'b') #set/save ... e2 = Vertex() e2.a.x = ax = 4 e2.a_y = ay = 12 e2.b.x = 3 e2.b.y = by = 123 assert e2.a.x == e2.a_x == ax assert e2.b.y == e2.b_y == by ... #query print session.query( Vertex).filter( Vertex.a.x 6 ).all() print session.query( Vertex).filter( Vertex.a_x 6 ).all() so far so good. now this one obviously wont work as such - i dont know how to make a arbitrary descriptor behave like a column_expression.. should i inherit interfaces.PropComparator? (hi Eric) print session.query( Vertex).filter( Vertex.a == whatever( 6,12) ).all() 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] Concatenating column names and text() clauses
Hello. I'm trying to writing something to generate full text searches for postgres. Here's the function I've got so far: from sqlalchemy import sql import operator def full_text(fields, text): def alternate(items): for i in items[:-1]: yield i yield sql.text( ' ' ) yield items[-1] return %s @@ to_tsquery('%s') % ( sql.func.to_tsvector( reduce(operator.add, alternate(fields)) ), text) You pass it a list of columns to match against and a full-text string to search with, and it returns a string that you can use in a filter() clause. It works fine if you only pass one or two column names--any more than that, and it dies. At first, I thought it was something wrong with my generator, but it turns out there's something wrong with the way I'm concatenating columns and raw text--that, or there's a bug there. Below is a simple example of what goes wrong. from sqlalchemy import * table1 = Table('table1', MetaData(), Column('col1', String()), Column('col2', String()), Column('col3', String()), ) #these work print table1.c.col1 + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 #these don't print table1.c.col1 + table1.c.col2 + text('sdf') print table1.c.col1 + table1.c.col2 + table1.c.col3 + text('sdf') print table1.c.col1 + text('sdf') + table1.c.col2 + text('sdf') print table1.c.col1 + text('sdf') + text('sdf') The ones that don't work die with AttributeError: 'NoneType' object has no attribute 'adapt_operator' on line 1328 in sqlachemy/sql/ expression.py Is this a bug, or am I doing this wrong? And all that aside, is there an existing way to generate a full-text search like that? Thanks, Jeff --~--~-~--~~~---~--~~ 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: Concatenating column names and text() clauses
if u start with the text, would it work? text(abc) + column text(abc) + text(dsa) text(abc) + column + text(abc) text(abc) + column1 + column2 On Thursday 21 August 2008 23:28:54 Jeff wrote: Hello. I'm trying to writing something to generate full text searches for postgres. Here's the function I've got so far: from sqlalchemy import sql import operator def full_text(fields, text): def alternate(items): for i in items[:-1]: yield i yield sql.text( ' ' ) yield items[-1] return %s @@ to_tsquery('%s') % ( sql.func.to_tsvector( reduce(operator.add, alternate(fields)) ), text) You pass it a list of columns to match against and a full-text string to search with, and it returns a string that you can use in a filter() clause. It works fine if you only pass one or two column names--any more than that, and it dies. At first, I thought it was something wrong with my generator, but it turns out there's something wrong with the way I'm concatenating columns and raw text--that, or there's a bug there. Below is a simple example of what goes wrong. from sqlalchemy import * table1 = Table('table1', MetaData(), Column('col1', String()), Column('col2', String()), Column('col3', String()), ) #these work print table1.c.col1 + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 #these don't print table1.c.col1 + table1.c.col2 + text('sdf') print table1.c.col1 + table1.c.col2 + table1.c.col3 + text('sdf') print table1.c.col1 + text('sdf') + table1.c.col2 + text('sdf') print table1.c.col1 + text('sdf') + text('sdf') The ones that don't work die with AttributeError: 'NoneType' object has no attribute 'adapt_operator' on line 1328 in sqlachemy/sql/ expression.py Is this a bug, or am I doing this wrong? And all that aside, is there an existing way to generate a full-text search like that? Thanks, Jeff --~--~-~--~~~---~--~~ 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: declarative
On Thu, 2008-08-21 at 16:08 +0200, Gaetan de Menten wrote: Everyone else will eventually grow out of it. That's quite a bold claim... Ok, Elixir is not your style, that's fine. Also, Elixir certainly doesn't suit every project out there, I'm aware of that. But implying it's not worth it for anybody is well... uninformed. Just don't bash something you probably don't really know. Sorry if that came across harsh, I was only speaking about my expirience and impression ofcourse. regards -jj --~--~-~--~~~---~--~~ 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: declarative
well, if u want something that looks simpler but is actualy quite more complex/twisted inside, try dbcook.sf.net. it tries to hide _all the sql-schema stuff for u. but it's definitely not for faint-hearted, no time to brush it up... even the examples look like a battle field. http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/usage/example/ svilen --~--~-~--~~~---~--~~ 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: Concatenating column names and text() clauses
On Aug 21, 2008, at 4:28 PM, Jeff wrote: Hello. I'm trying to writing something to generate full text searches for postgres. Here's the function I've got so far: from sqlalchemy import sql import operator def full_text(fields, text): def alternate(items): for i in items[:-1]: yield i yield sql.text( ' ' ) yield items[-1] return %s @@ to_tsquery('%s') % ( sql.func.to_tsvector( reduce(operator.add, alternate(fields)) ), text) You pass it a list of columns to match against and a full-text string to search with, and it returns a string that you can use in a filter() clause. It works fine if you only pass one or two column names--any more than that, and it dies. At first, I thought it was something wrong with my generator, but it turns out there's something wrong with the way I'm concatenating columns and raw text--that, or there's a bug there. Below is a simple example of what goes wrong. from sqlalchemy import * table1 = Table('table1', MetaData(), Column('col1', String()), Column('col2', String()), Column('col3', String()), ) #these work print table1.c.col1 + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 + table1.c.col3 print table1.c.col1 + text('sdf') + table1.c.col2 #these don't print table1.c.col1 + table1.c.col2 + text('sdf') print table1.c.col1 + table1.c.col2 + table1.c.col3 + text('sdf') print table1.c.col1 + text('sdf') + table1.c.col2 + text('sdf') print table1.c.col1 + text('sdf') + text('sdf') The ones that don't work die with AttributeError: 'NoneType' object has no attribute 'adapt_operator' on line 1328 in sqlachemy/sql/ expression.py Is this a bug, or am I doing this wrong? And all that aside, is there an existing way to generate a full-text search like that? in general, text() is intended primarily for fully constructed SQL statements, and does not implement the semantics of an element used within an expression. For individual literal components, use the literal() function which produces a bind parameter, which will have all the semantic properties of any other column-oriented expression element. if that doesn't resolve your issue we can try again with something more concrete. --~--~-~--~~~---~--~~ 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: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Thanks Jason. Downloaded R5051, it works fine! Cheers, Harish On Thu, Aug 21, 2008 at 7:58 PM, jason kirtland [EMAIL PROTECTED] wrote: Thanks for the traceback. Give r5050 a try. Cheers, Jason Harish K Vishwanath wrote: Hello Michael, Thanks for your input! I got the latest trunk from SVN. However, if my app specific baseclass is an old style class, it still breaks., this time in orm\attributes.py Traceback (most recent call last): File SqlDB_Test.py, line 9, in ? dbo = SqlDB(SqlDB_Test.Sqlite,c:\\testdbs) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 77, in __init_ _ self.initSetup(echo) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 115, in initSe tup elixir.setup_all(True) File d:\recogsys\src\python\rsiterm\__init__.py, line 145, in setup_all File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\__init__.py, line 643, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 197, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 852, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1494, in create_manager_for_cls manager = factory(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1047, in __init__ cls_state = manager_of_class(base) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1511, in manager_of_class finder = self.manager_finders[cls] File C:\Python24\lib\weakref.py, line 219, in __getitem__ return self.data[ref(key)] TypeError: cannot create weak reference to 'classobj' object This error goes away when I make my app baseclass as a new style class. It is not giving any problems with Exceptions class in Py2.4 though. Could this be a possible issue? On Wed, Aug 20, 2008 at 9:28 PM, Michael Bayer [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: On Aug 20, 2008, at 11:52 AM, Harish K Vishwanath wrote: Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? no worries...use the latest trunk, which will ultimately be released either as 0.5beta4 or 0.5.0. http://0.5.0. -- Regards, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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] Facing Invalid Request Error in 0.5beta4r5051
Hello, I am getting a sa.exc.InvalidRequestError in SALA 0.5beta4, which never happened in SQLA 0.4.6 SQLA 0.4.6 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, transactional=True) SQLA 0.5beta4 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, autocommit=False) Apart from this, as per the documentation the SQLA 0.5 session is autoexpire=True, which expires all objects after a commit call. Below is the traceback of the exception : file:///E:/ChitradaChandrama/ File SchemaTest.py, line 193, in ? user = myDB.CreateTestUser(msg) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 633, in Create TestUser oiUser.SetAuthority('Authority', self) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 154, in SetA uthority self.PostInteraction(rsiDB, 'Authority', str(val), targetUserID) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 1056, in Pos tInteraction rsiDB.AddInteraction(iao) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 418, in AddInt eraction return interaction.InteractionID File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 135, in __get__ return self.impl.get(instance_state(instance)) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 319, in get value = callable_() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 877, in __call__ class_manager.deferred_scalar_loader(self, [ File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\mapper.py, line 1701, in _load_scalar_attributes result = session.query(mapper)._get(identity_key, refresh_state=state, only_ load_props=attribute_names) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1181, in _get return q.all()[0] File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 979, in all return list(self) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1044, in __iter__ return self._execute_and_instances(context) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1047, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 744, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 711, in __connection return self.transaction._connection_for_bind(engine) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 309, in _connection_for_bind self._assert_is_active() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 243, in _assert_is_active raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: The transaction is inactive due to a rollbac k in a subtransaction. Issue rollback() to cancel the transaction. The line rsiDB.AddInteraction(iao), calls a commit() after adding the object. In SQLA0.5beta4, the object which was attached to the session is expired after commit? The next statment which is trying to return object.id, is issuing another query but is getting an inactive transaction and hence the error. Correct? This doesn't happen in SQLA 0.4.6. How can I fix this error? Please note that I am handling all exceptions that can be raised by a commit() call , issuing a rollback and reporting them. But I dont seen any rollbacks at all, but even then the exception says so. Appreciate any inputs. Thanks, Harish --~--~-~--~~~---~--~~ 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] Fwd: Facing Invalid Request Error in 0.5beta4r5051
The error goes away when I make the session expire_on_commit=False., But its a nice feature to have, how can I fix the exception below retaining this feature? -- Forwarded message -- From: Harish K Vishwanath [EMAIL PROTECTED] Date: Fri, Aug 22, 2008 at 11:04 AM Subject: Facing Invalid Request Error in 0.5beta4r5051 To: sqlalchemy@googlegroups.com Hello, I am getting a sa.exc.InvalidRequestError in SALA 0.5beta4, which never happened in SQLA 0.4.6 SQLA 0.4.6 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, transactional=True) SQLA 0.5beta4 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, autocommit=False) Apart from this, as per the documentation the SQLA 0.5 session is autoexpire=True, which expires all objects after a commit call. Below is the traceback of the exception : File SchemaTest.py, line 193, in ? user = myDB.CreateTestUser(msg) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 633, in Create TestUser oiUser.SetAuthority('Authority', self) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 154, in SetA uthority self.PostInteraction(rsiDB, 'Authority', str(val), targetUserID) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 1056, in Pos tInteraction rsiDB.AddInteraction(iao) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 418, in AddInt eraction return interaction.InteractionID File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 135, in __get__ return self.impl.get(instance_state(instance)) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 319, in get value = callable_() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 877, in __call__ class_manager.deferred_scalar_loader(self, [ File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\mapper.py, line 1701, in _load_scalar_attributes result = session.query(mapper)._get(identity_key, refresh_state=state, only_ load_props=attribute_names) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1181, in _get return q.all()[0] File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 979, in all return list(self) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1044, in __iter__ return self._execute_and_instances(context) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1047, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 744, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 711, in __connection return self.transaction._connection_for_bind(engine) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 309, in _connection_for_bind self._assert_is_active() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 243, in _assert_is_active raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: The transaction is inactive due to a rollbac k in a subtransaction. Issue rollback() to cancel the transaction. The line rsiDB.AddInteraction(iao), calls a commit() after adding the object. In SQLA0.5beta4, the object which was attached to the session is expired after commit? The next statment which is trying to return object.id, is issuing another query but is getting an inactive transaction and hence the error. Correct? This doesn't happen in SQLA 0.4.6. How can I fix this error? Please note that I am handling all exceptions that can be raised by a commit() call , issuing a rollback and reporting them. But I dont seen any rollbacks at all, but even then the exception says so. Appreciate any inputs. Thanks, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---