[sqlalchemy] SQLAlchemy and SQLRelay
Is it possible to use SA with SQLRelay? --~--~-~--~~~---~--~~ 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: SQLAlchemy and SQLRelay
Is it possible to use SA with SQLRelay? I Think yes if you are using MySQL or PostgreSQL, they have a Client Native API Wrapper, so you can try it. For others, I suggest the SA Core team to write the driver fot that client API, because it can be very useful in many cases. Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ 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] MapperExtension.after_update and Session.merge(..., dont_load=True).
Hi all, sometime since version 0.4.2, the after_update hook of a MapperExtension fires even if no SQL UPDATE statement is generated. Is this a bug or a feature? In my case, an object is marked as dirty because a backref has changed, not because of any change in the object itself. A merge(..., dont_load=True) is also part of the mix. If it's a bug, I'll try to provide more details. Best regards Klaus --~--~-~--~~~---~--~~ 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] Attaching a 'pre-created' class to a session?
It seems there must be something I'm missing here, so hopefully other sets of eyes will spot an obvious mistake. I have a series of objects that may-or-may not be persistent: some will be created and stored to a db, some will be retrieved from the db, maybe modified and updated, others will never go anywhere near the db. (I have a series of programs using the same objects, only some of which need to interact with the db.) However, I'm A simple test case. Given this code: class Sample (object): def __init__ (self, id=None, title=None, description=None): self.id = id self.title = title self.description = description class Conn (object): def __init__ (self): conn_uri = CONN_URI_TMPL % TESTDB_CONNINFO self.SA_ENGINE = create_engine (conn_uri) self.SA_METADATA = MetaData (conn_uri) self.SA_ENGINE.echo = True Session = sessionmaker (bind=self.SA_ENGINE) self.SA_SESSION = Session() self.SA_QUERY = self.SA_SESSION.query self.SAMPLETABLE = Table ('samples', self.SA_METADATA, Column ('id', Unicode(32), primary_key=True), Column ('title', Unicode(32)), Column ('description', Unicode(32)), ) self.SA_METADATA.create_all (checkfirst=True) clear_mappers() mapper (Sample, self.SAMPLETABLE) Sample is the class I'd like to be able to persist if needed. Conn just encapsulates the connection for test purposes. Now if I do this: c = Conn() s1 = Sample() s1.id = 'foo' c.SA_SESSION.save_or_update (s1) c.SA_SESSION.flush() all is well. But if I create the Sample before the connection, it doesn't work: s1 = Sample() s1.id = 'foo' c = Conn() c.SA_SESSION.save_or_update (s1) c.SA_SESSION.flush() AttributeError: 'ColumnProperty' object has no attribute 'key' So, how can I persist an object constructed before the connection is established? Or is it necessary to do all work either within or without of the context of a session? Thanks -- Dr Paul-Michael Agapow: VieDigitale / Inst. for Animal Health [EMAIL PROTECTED] / [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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] problems with filter_by()
Hi, I recently upgrade from sqlalchemy 0.3.10 to 0.4.2p3. I have a method like this: def getPlanillaDet(self, plan_id): return session.query(PlanillaDet).filter_by(Planilladet.c.plan_id==plan_id).all() Now, after update, when I try to execute this method, I get an exception with the next message: File V:\nacer\bin\common\services.py, line 192, in get return session.query(PlanillaDet).filter_by(Planilladet.c.plan_id==plan_id).all() TypeError: filter_by() takes exactly 1 argument (2 given) What is the problem here ? Thanks in advance. --~--~-~--~~~---~--~~ 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: MapperExtension.after_update and Session.merge(..., dont_load=True).
On Jan 14, 2008, at 5:30 AM, klaus wrote: Hi all, sometime since version 0.4.2, the after_update hook of a MapperExtension fires even if no SQL UPDATE statement is generated. Is this a bug or a feature? this is a feature, the save_obj() method is including your object but no UPDATE is emitted because no column-mapped values have changed. However youll notice that before_update() *is* being called, which has to since we dont know yet if we're doing an UPDATE at that point (and before_update() can even change that outcome), so its consistent that after_update() should be called for every before_update() method. In my case, an object is marked as dirty because a backref has changed, not because of any change in the object itself. A merge(..., dont_load=True) is also part of the mix. If it's a bug, I'll try to provide more details. if youd like to do the same check that save_obj() is doing on an object for changed, just do this: session.is_modified(instance, include_collections=False) --~--~-~--~~~---~--~~ 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: problems with filter_by()
On Jan 14, 2008, at 9:38 AM, maxi wrote: Hi, I recently upgrade from sqlalchemy 0.3.10 to 0.4.2p3. I have a method like this: def getPlanillaDet(self, plan_id): return session .query(PlanillaDet).filter_by(Planilladet.c.plan_id==plan_id).all() Now, after update, when I try to execute this method, I get an exception with the next message: File V:\nacer\bin\common\services.py, line 192, in get return session .query(PlanillaDet).filter_by(Planilladet.c.plan_id==plan_id).all() TypeError: filter_by() takes exactly 1 argument (2 given) What is the problem here ? use filter() for clause-based expressions, filter_by() only takes **kwargs now. --~--~-~--~~~---~--~~ 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: problems with filter_by()
Thaks for your help. Can you post an example over how to use filter and filter_by in new sqlalchemy versions? Is your recommendation included in 0.3 to 0.4 migration guide? Why this change? Regards. --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 10:44 AM, Alexandre Conrad wrote: Michael Bayer wrote: I came up with a very easy way to implement this which I'd like you to try out in rev 4060. So far I've tested with a basic joined table inheritance setup. All you do is place class-mapped attributes directly in the join() arguments along with strings. and thats it ! so it looks like: session.query(Media).join(['catalog', CatalogChannel.channel]) The class-attributes can be freely intermixed with the existing string- based attributes. Technically you can place any class-attribute you want in there but it only makes sense if it can be joined against the immediately preceding attribute or parent mapper. I'm not sure if that restriction could change eventually. model.Media.query.join([catalog, model .CatalogChannel .channel ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() generates: SELECT files.id AS files_id, medias.id AS medias_id, files.name AS files_name, files.mime AS files_mime, files.date AS files_date, files.size AS files_size, files.checksum AS files_checksum, files.description AS files_description, files.type AS files_type, medias.id_catalog AS medias_id_catalog FROM catalog_channels, files INNER JOIN medias ON files.id = medias.id INNER JOIN catalogs ON catalogs.id = medias.id_catalog INNER JOIN channels ON channels.id = catalog_channels.id_channel WHERE catalog_channels.id_channel = %s ORDER BY files.name whats that filter() trying to accomplish ? please work this into a full test case using SQLite so I can run through it. --~--~-~--~~~---~--~~ 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: eagerloading polymorphic mapper
On Jan 14, 2008, at 8:41 AM, svilen wrote: i have, say, base class A, inherited by two children B and C. B has an attribute/relation 'address', A and C do not have it. So i had a query(A).eagerload( 'address') and that did work before r3912. But later it gives an error - mapper|A has no property 'address'. Any hint how to do it now? what kind of inheritance/mapping from A-B ? i cant really imagine any way that kind of eager load could have worked since the address property of B does not (and has never) get consulted in that case. --~--~-~--~~~---~--~~ 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] Query object behavior for methods all() and one()
I am a bit confused by the behavior for the methods all() and one() if the Query would return an empty result set. In the case of all() it returns an empty list whereas one() will throw an exception (sqlalchemy.exceptions.InvalidRequestError). I am sure there was a reason to implement as it is now but wouldn't it be more convenient to return simply None (or an empty String) and throw an exception only if more than one row would be returned? An empty result set as such is valid and shouldn't be treated as an error. --~--~-~--~~~---~--~~ 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: Query object behavior for methods all() and one()
all() returns whatwever is there, 0, 1, n first() returns first if any or None one() asserts there's exactly 1 On Monday 14 January 2008 18:23:28 Adrian wrote: I am a bit confused by the behavior for the methods all() and one() if the Query would return an empty result set. In the case of all() it returns an empty list whereas one() will throw an exception (sqlalchemy.exceptions.InvalidRequestError). I am sure there was a reason to implement as it is now but wouldn't it be more convenient to return simply None (or an empty String) and throw an exception only if more than one row would be returned? An empty result set as such is valid and shouldn't be treated as an error. --~--~-~--~~~---~--~~ 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: eagerloading polymorphic mapper
On Monday 14 January 2008 17:19:14 Michael Bayer wrote: On Jan 14, 2008, at 8:41 AM, svilen wrote: i have, say, base class A, inherited by two children B and C. B has an attribute/relation 'address', A and C do not have it. So i had a query(A).eagerload( 'address') and that did work before r3912. But later it gives an error - mapper|A has no property 'address'. Any hint how to do it now? what kind of inheritance/mapping from A-B ? i cant really imagine any way that kind of eager load could have worked since the address property of B does not (and has never) get consulted in that case. plain joined?... hmm. maybe it did not really work (eagerly) but lazy-load has fired instead... seems that's the case. anyway. some way to accomplish such thing? --~--~-~--~~~---~--~~ 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: Query object behavior for methods all() and one()
On Jan 14, 2008, at 11:23 AM, Adrian wrote: I am a bit confused by the behavior for the methods all() and one() if the Query would return an empty result set. In the case of all() it returns an empty list whereas one() will throw an exception (sqlalchemy.exceptions.InvalidRequestError). I am sure there was a reason to implement as it is now but wouldn't it be more convenient to return simply None (or an empty String) and throw an exception only if more than one row would be returned? An empty result set as such is valid and shouldn't be treated as an error. use query.first() instead of query.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: eagerloading polymorphic mapper
On Jan 14, 2008, at 11:29 AM, svilen wrote: On Monday 14 January 2008 17:19:14 Michael Bayer wrote: On Jan 14, 2008, at 8:41 AM, svilen wrote: i have, say, base class A, inherited by two children B and C. B has an attribute/relation 'address', A and C do not have it. So i had a query(A).eagerload( 'address') and that did work before r3912. But later it gives an error - mapper|A has no property 'address'. Any hint how to do it now? what kind of inheritance/mapping from A-B ? i cant really imagine any way that kind of eager load could have worked since the address property of B does not (and has never) get consulted in that case. plain joined?... hmm. maybe it did not really work (eagerly) but lazy-load has fired instead... seems that's the case. anyway. some way to accomplish such thing? no ! this the same issue with the Channel-CatalogChannel thing, your query is against A...attributes that are only on B don't enter into the equation here.But also, if youre using select_table, we dont yet support eager loads from a polymorphic-unioned mapper in any case (though we are close). --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 10:44 AM, Alexandre Conrad wrote: model.Media.query.join([catalog, model .CatalogChannel .channel ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() is CatalogChannel.channel a self referential relation to another Channel ? the classes you use in filter() are usually of the type that channel would be here. generates: SELECT files.id AS files_id, medias.id AS medias_id, files.name AS files_name, files.mime AS files_mime, files.date AS files_date, files.size AS files_size, files.checksum AS files_checksum, files.description AS files_description, files.type AS files_type, medias.id_catalog AS medias_id_catalog FROM catalog_channels, files INNER JOIN medias ON files.id = medias.id INNER JOIN catalogs ON catalogs.id = medias.id_catalog INNER JOIN channels ON channels.id = catalog_channels.id_channel WHERE catalog_channels.id_channel = %s ORDER BY files.name which returns, with MySQL: 1054, Unknown column 'catalog_channels.id_channel' in 'on clause' also the actual error here is a known MySQL 5 issue, but the SQL is still not what SQLAlchemy would want to produce. --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 12:04 PM, Michael Bayer wrote: On Jan 14, 2008, at 11:59 AM, Michael Bayer wrote: On Jan 14, 2008, at 10:44 AM, Alexandre Conrad wrote: model.Media.query.join([catalog, model .CatalogChannel .channel ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() like, are you sure you dont want to just say: model .Media .query .join ([catalog ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() ? that is if you want the Media which contains a CatalogChannel with a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. oh also, this might be complicating thingsthe above query I just gave you will only work at the moment if you are using select_table on your Catalog mapper to define a polymorphic join. Its possible that you could define select_table and just go with the above, simpler query (if my particular guess here is correct as to what youre trying to accomplish). or if not using select_table, force it manually like this: session .query (Media ).select_from (files .join (media ).join (catalog).join(catalog_channel)).filter(CatalogChannel.id_channel==foo) --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
Mike, Michael Bayer wrote: a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. Enough guessing, here's the full test case with description of what I'm trying to do. :) Although, I wasn't able to make it run with sqlite, so it's running a under a foo table with MySQL. (another hidden bug, I'm getting (IntegrityError) medias.id may not be NULL). Regards, -- Alexandre CONRAD --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- SA_joined_inherited_class.py Description: application/python
[sqlalchemy] Re: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 12:12 PM, Alexandre Conrad wrote: Mike, Michael Bayer wrote: a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. Enough guessing, here's the full test case with description of what I'm trying to do. :) Although, I wasn't able to make it run with sqlite, so it's running a under a foo table with MySQL. (another hidden bug, I'm getting (IntegrityError) medias.id may not be NULL). thats not hidden. SQLite cannot autoincrement primary key columns if the table contains a composite primary key which is the case 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 11:59 AM, Michael Bayer wrote: On Jan 14, 2008, at 10:44 AM, Alexandre Conrad wrote: model.Media.query.join([catalog, model .CatalogChannel .channel ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() like, are you sure you dont want to just say: model .Media .query .join ([catalog ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() ? that is if you want the Media which contains a CatalogChannel with a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. oh also, this might be complicating thingsthe above query I just gave you will only work at the moment if you are using select_table on your Catalog mapper to define a polymorphic join. Its possible that you could define select_table and just go with the above, simpler query (if my particular guess here is correct as to what youre trying to accomplish). --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
Alexandre Conrad wrote: under a foo table with MySQL. (another hidden bug, I'm getting a foo schema/db, not table. -- Alexandre CONRAD --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 10:44 AM, Alexandre Conrad wrote: model.Media.query.join([catalog, model .CatalogChannel .channel ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() like, are you sure you dont want to just say: model .Media .query .join ([catalog ]).filter (model.CatalogChannel.c.id_channel==c.playlist.id_channel).all() ? that is if you want the Media which contains a CatalogChannel with a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
Michael Bayer wrote: thats not hidden. SQLite cannot autoincrement primary key columns if the table contains a composite primary key which is the case here. Ah, yes. Plus, I don't need composite primary_key here, it's articact from an old many-to-many secondary table (which I usually set as primary_key=True on both columns). Regards, -- Alexandre CONRAD --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 12:12 PM, Alexandre Conrad wrote: Mike, Michael Bayer wrote: a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. Enough guessing, here's the full test case with description of what I'm trying to do. :) Although, I wasn't able to make it run with sqlite, so it's running a under a foo table with MySQL. (another hidden bug, I'm getting (IntegrityError) medias.id may not be NULL). ok, you can also do it like this: select_table = catalog_table.outerjoin(catalog_channel_table).select().alias('pjoin') catalog_mapper = mapper(Catalog, catalog_table, select_table=select_table, polymorphic_on=catalog_table.c.type, polymorphic_identity=catalog, properties={ medias:relation(Media, backref=catalog, cascade=all, delete-orphan, ), }, ) print Media .query .join ('catalog').filter(CatalogChannel.id_channel==playlist.id_channel).all() Still working on getting select_table to not have to be aliased like that. --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
Michael Bayer wrote: your best bet with this mapping right now is: print Media .query .select_from (media_table .join (catalog_table ).join (catalog_channel_table )).filter(CatalogChannel.c.id_channel==playlist.id_channel).all() which is really how select_from() was intended to be used. This works with SQLite, but not MySQL: (1054, Unknown column 'catalog_channels.id_channel' in 'on clause') You'd say this is a MySQL bug ? Darn... Also, select_from still makes us play with tables. At first, I was looking at an alternative to fully use classes rather than tables for doing the joins. I remember I already played with that select_from syntax, which was working. Regards, -- Alexandre CONRAD --~--~-~--~~~---~--~~ 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: MapperExtension.after_update and Session.merge(..., dont_load=True).
Nice, thanks! On 14 Jan., 16:16, Michael Bayer [EMAIL PROTECTED] wrote: On Jan 14, 2008, at 5:30 AM, klaus wrote: Hi all, sometime since version 0.4.2, the after_update hook of a MapperExtension fires even if no SQL UPDATE statement is generated. Is this a bug or a feature? this is a feature, the save_obj() method is including your object but no UPDATE is emitted because no column-mapped values have changed. However youll notice that before_update() *is* being called, which has to since we dont know yet if we're doing an UPDATE at that point (and before_update() can even change that outcome), so its consistent that after_update() should be called for every before_update() method. In my case, an object is marked as dirty because a backref has changed, not because of any change in the object itself. A merge(..., dont_load=True) is also part of the mix. If it's a bug, I'll try to provide more details. if youd like to do the same check that save_obj() is doing on an object for changed, just do this: session.is_modified(instance, include_collections=False) --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 12:12 PM, Alexandre Conrad wrote: Mike, Michael Bayer wrote: a certain id_channel. otherwise im still having trouble wrapping my head around what youre trying to do there. Enough guessing, here's the full test case with description of what I'm trying to do. :) Although, I wasn't able to make it run with sqlite, so it's running a under a foo table with MySQL. (another hidden bug, I'm getting (IntegrityError) medias.id may not be NULL). your best bet with this mapping right now is: print Media .query .select_from (media_table .join (catalog_table ).join (catalog_channel_table )).filter(CatalogChannel.c.id_channel==playlist.id_channel).all() which is really how select_from() was intended to be used. the select_table option should be working here, which would make this super easy, but its not - will investigate more closely. --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
Mike, My day is over, I'm leaving the office. I'll read your replies tomorrow. Thanks for taking some time one that. Regards, -- Alexandre CONRAD --~--~-~--~~~---~--~~ 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: filter() on inherited class doesn't point to the correct table
On Jan 14, 2008, at 12:44 PM, Alexandre Conrad wrote: Michael Bayer wrote: your best bet with this mapping right now is: print Media .query .select_from (media_table .join (catalog_table ).join (catalog_channel_table )).filter(CatalogChannel.c.id_channel==playlist.id_channel).all() which is really how select_from() was intended to be used. This works with SQLite, but not MySQL: (1054, Unknown column 'catalog_channels.id_channel' in 'on clause') that doesnt sound right. taking out select_table, and doing: print Media .query .select_from (media_table .join (catalog_table ).join (catalog_channel_table )).filter(CatalogChannel.c.id_channel==playlist.id_channel).all() leads to the SQL: SELECT medias.id AS medias_id, medias.name AS medias_name, medias.id_catalog AS medias_id_catalog FROM medias JOIN catalogs ON catalogs.id = medias.id_catalog JOIN catalog_channels ON catalogs.id = catalog_channels.id WHERE catalog_channels.id_channel = ? ORDER BY medias.oid which is entirely acceptable (and works in mysql). --~--~-~--~~~---~--~~ 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: MapperExtension upgrade
On Jan 14, 2008, at 1:46 PM, maxi wrote: Hi, In new sqlalchemy version (0.4), the MapperExtension must return EXT_CONTINUE for each method. Now, all methods must return this const? For instance, I've the next extension for my mapper: class ConvenioExtension(MapperExtension): def create_instance(self, mapper, selectcontext, row, class_): return Convenio() Because I need create my owner class ever. Then, I have to return EXT_CONTINUE here? How? the above extension is correct. EXT_CONTINUE indicates the return value should be ignored, which is not what you want here. the rest of the MapperExtension methods which you dont override will handle themselves. --~--~-~--~~~---~--~~ 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] MapperExtension upgrade
Hi, In new sqlalchemy version (0.4), the MapperExtension must return EXT_CONTINUE for each method. Now, all methods must return this const? For instance, I've the next extension for my mapper: class ConvenioExtension(MapperExtension): def create_instance(self, mapper, selectcontext, row, class_): return Convenio() Because I need create my owner class ever. Then, I have to return EXT_CONTINUE here? How? TIA. --~--~-~--~~~---~--~~ 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] InvalidRequestError when I try to save object
Hi, Follwing with my 0.3 to 0.4 upgrade, now I get the next problem... When I try to save an object across my session, I get an InvalidRequestError exception with the message: File c:\programs\python25\lib\site-packages\sqlalchemy-0.4.2p3- py2.5.egg\sqlalchemy\orm\session.py, line 988, in _save_impl raise exceptions.InvalidRequestError(Instance '%s' is already persistent % mapperutil.instance_str(instance)) InvalidRequestError: Instance '[EMAIL PROTECTED]' is already persistent Why with 0.3 I had not this error? Any 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] Re: InvalidRequestError when I try to save object
On Jan 14, 2008, at 2:32 PM, maxi wrote: Hi, Follwing with my 0.3 to 0.4 upgrade, now I get the next problem... When I try to save an object across my session, I get an InvalidRequestError exception with the message: File c:\programs\python25\lib\site-packages\sqlalchemy-0.4.2p3- py2.5.egg\sqlalchemy\orm\session.py, line 988, in _save_impl raise exceptions.InvalidRequestError(Instance '%s' is already persistent % mapperutil.instance_str(instance)) InvalidRequestError: Instance '[EMAIL PROTECTED]' is already persistent Why with 0.3 I had not this error? use session.save_or_update() for an instance where you arent sure if its persistent or not. this is the same API as in 0.3, 0.3 just has a bug where no error is raised. --~--~-~--~~~---~--~~ 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: InvalidRequestError when I try to save object
I must use save_update alone or save_update + flush ? --~--~-~--~~~---~--~~ 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: mssql connection uri
The mssql URI is going to take the same conceptual form as any other sqlalchemry dburi. The format is documented and available in the SA docs. We can't give you the exact URI, because it's going to contain things that are specific to your application, like database name, password, etc. ODBC under Linux I can't help you with (yet). Your best bet for MSSQL + *nix is going to be using pymssql for now. Pymssql (and any other unix-to-MSSQL connection scheme), is going to require FreeTDS to establish the basic network connection. Installing FreeTDS on Linux is going to be different for various distributions, but in general is available via normal package repositories. From your sig, I'll assume you're looking for a Debian dpkg package. I know there's one for Ubuntu, which should install on Debian, and there may be a straight-up Debian package in their repositories as well. Make sure you get a fairly recent version, as older versions assumed a Sybase set of connection parameters instead of MSSQL. The FreeTDS docs outline the issue with the various protocol versions. If you have the protocol version set wrong, then MSSQL dates won't transfer correctly. Much of this information is on the SQLAlchemy wiki under database notes, check there as well. HTH, Rick --~--~-~--~~~---~--~~ 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: InvalidRequestError when I try to save object
flush() works exactly as before. the difference that Mike is pointing out is that 0.3 allowed already-persisted objects to be re-added, which was a bug that is now fixed. Using save_or_update() instead of save() will help you avoid triggering the error when the object you're trying to .save() is already added. --~--~-~--~~~---~--~~ 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] mssql connection uri
Hello, I need to extend my turbogears app to get some records from ms sql. Do you guys know how to setup the ms sql dbi uri to work with sqlalchemy? What connection uri do I use? How do I setup unix odbc for it? Anything else I need? Can you give me exact instructions? Thanks, Lucas -- -- VMware Server On Debian http://wiki.debian.org/Manual-Howto#head-c9e998d4806797452cd58fce417b6fb00fbc60be TurboGears from start to finish: http://www.lucasmanual.com/mywiki/TurboGears --~--~-~--~~~---~--~~ 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: InvalidRequestError when I try to save object
But, is my design mistake ? I must use ever save_or_update() function? In my case, I have two process working over the same class of bussines object. I do a query, which return me an object list and I call to other function which pass one parameter (id) and this function do other query over the same class. i.e.: Table - Person person_list = my_service.get_people() for p in person_list: process_person(p.id) def process_person(id): person = my_service.get_person() do something with person session.save(person) # here, raise exception: InvalidRequestError: Instance... already persistent session.flush([person]) Now, I chage session.save_or_update(person), and this work fine. --~--~-~--~~~---~--~~ 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: InvalidRequestError when I try to save object
Well, the my_service.get_people() most likely uses a query to retrieve those people from the database, right? That query would have the effect of putting those results into the session as persistent objects. When you call session.save() on one of those already-persisted objects, the session checks to see if that object is already being tracked. It is, because it was just loaded from the database as a persistent object. So,that triggers the error. If you know for sure that the person object was loaded from a query, then there's no need to .save() the object at all: it's already being tracked. However, there is no harm in using session.save_or_update(), as that would check to see if the object was already persisted, find that it was, and then do nothing anyway. --~--~-~--~~~---~--~~ 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] SqlAlchemy 0.4 and py2exe. Problem solved?
Is solved the problem involved in py2exe and sqlalchemy 0.3 ? Can I use py2exe without problem with loggin module? --~--~-~--~~~---~--~~ 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: Exclude Autogenerated Timestamp Column
Good points - although restructuring the database around integer PKs is out of the question at the moment and we also need to support operations where 'road shoot' databases are merged into our master database... so we do have one legitimate use for GUIDs :) If I run across a way to fetch auto-inserted GUIDs from MSSQL, I'll bring it forward.. but for now generating the id before insertion seems to be the way to go. cheers On Jan 12, 4:42 am, Ants Aasma [EMAIL PROTECTED] wrote: On Jan 12, 4:43 am, Rick Morrison [EMAIL PROTECTED] wrote: My experience with GUID PKs is that they almost always cause more troubles than they purport to solve, and 99% of the time a plain Integer PK will work just fine instead. The two rare exceptions are with multi-database synchronization (and even there integer PKs can work fine with an additional 'source' discriminator column) and humungo databases where overflowing a bigint col is a real fear. A bit offtopic, but I can't imagine a situation where overflowing a bigint col would be feasible. Even if you generate 1 billion rows per second, you still have about 300 years worth of keys available. Ants Aasma --~--~-~--~~~---~--~~ 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] Large eager fetches not so eager?
This is going to sound kind of strange, but I've noticed that sometimes when doing fairly large eager loads, that not everything always loads. So running, say custlist = S.query(Customer).options(eagerload('addresses'), eagerload('properties')).filter(Customer.id.in_([...])).all() and fetching 120 objects, I'll find that 0-89 have properly eagerloaded, but when I touch custlist[90].addresses, (or anything higher than 90), it triggers a lazy load on the addresses. anyone else seen anything like this? Rick --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
Update: it's not the length of the fetch, a smaller fetch still has holes it it. Looks as if something might be short-circuiting the SA internal join? --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
On Jan 14, 2008, at 8:11 PM, Rick Morrison wrote: This is going to sound kind of strange, but I've noticed that sometimes when doing fairly large eager loads, that not everything always loads. So running, say custlist = S.query(Customer).options(eagerload('addresses'), eagerload('properties')).filter( Customer.id.in_([...])).all() and fetching 120 objects, I'll find that 0-89 have properly eagerloaded, but when I touch custlist[90].addresses, (or anything higher than 90), it triggers a lazy load on the addresses. anyone else seen anything like this? this can occur with certain kinds of joins, particularly self- referential joins, where the same entity appears more than once in a result set (at different levels)although we have unit tests which ensure that this doesnt happen. the other case is if an entity is already present in the session; by default nothing gets written to it (including collections). so the short test case here would be helpful (also step through debugging output to see what decisions its making). --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
I had already put together a short test case which as usual is of course working fine, but it's greatly simpler than the in-application use and uses sqlite instead of MSSQL, so I'll bang on it from time to time as I've got a few seconds and I'll see where it goes. I did notice some behavior that might give a clue. Whenever an eagerly loaded item is missing in the list of results, so are all the values that follow. For example, if I shorten my original list to fifty items, 0-43 might be ok. After item 43, then *every* remaining item is missing, so I would think that it's something that traverses the list of results and once it breaks, it stops the traverse. as far as I know, none of the otherwise eagerly loaded items are already mapped, and the joins are not self-referential. It's a three-way join of three different tables as outlined in the orig post. So it might be something new. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---