[sqlalchemy] passive_deletes/updates with sqlite
hello friends, as sqlite has recently introduced support for on delete/update cascade, i'd like to implement the passive_* functionality for this driver too. please give me a hint where to start. best regards, alex -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Python's reserved keywords as column names
On 10 сен, 17:15, King Simon-NFHD78 simon.k...@motorola.com wrote: Hi Andrey, See the section in the docs 'Attribute Names for Mapped Columns': http://www.sqlalchemy.org/docs/orm/mapper_config.html#attribute-names-fo r-mapped-columns Hope that helps, Simon Well, this leads to the only way to map in my case named 'Declarative'. Because it would fail on mapper(Class, table, properties = { '_from': table.c.from }) Could non-declarative way for mapping python's reserved keywords as column names be scheduled as a bug or enhancement request ? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
RE: [sqlalchemy] Re: Python's reserved keywords as column names
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Andrey Semyonov Sent: 10 September 2010 14:35 To: sqlalchemy Subject: [sqlalchemy] Re: Python's reserved keywords as column names On 10 сен, 17:15, King Simon-NFHD78 simon.k...@motorola.com wrote: Hi Andrey, See the section in the docs 'Attribute Names for Mapped Columns': http://www.sqlalchemy.org/docs/orm/mapper_config.html#attribute- names-fo r-mapped-columns Hope that helps, Simon Well, this leads to the only way to map in my case named 'Declarative'. Because it would fail on mapper(Class, table, properties = { '_from': table.c.from }) Could non-declarative way for mapping python's reserved keywords as column names be scheduled as a bug or enhancement request ? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. The 'c' collection on a Table object allows dictionary-style access, so you should be able to use: mapper(Class, table, properties = { '_from': table.c['from'] }) Even if that didn't work, you could always use Python's getattr function: mapper(Class, table, properties = { '_from': getattr(table.c, 'from') }) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Python's reserved keywords as column names
On Sep 10, 2010, at 9:35 AM, Andrey Semyonov wrote: On 10 сен, 17:15, King Simon-NFHD78 simon.k...@motorola.com wrote: Hi Andrey, See the section in the docs 'Attribute Names for Mapped Columns': http://www.sqlalchemy.org/docs/orm/mapper_config.html#attribute-names-fo r-mapped-columns Hope that helps, Simon Well, this leads to the only way to map in my case named 'Declarative'. Because it would fail on mapper(Class, table, properties = { '_from': table.c.from }) Could non-declarative way for mapping python's reserved keywords as column names be scheduled as a bug or enhancement request ? Option 1: mapper(C, t1, properties={'from_':t1.c['from']}) Option 2: t1 = Table('sometable', metadata, Column('from', Integer, key='from_')) t1.c.from_ these techniques are documented at: http://www.sqlalchemy.org/docs/core/schema.html#accessing-tables-and-columns http://www.sqlalchemy.org/docs/core/schema.html#sqlalchemy.schema.Column -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] passive_deletes/updates with sqlite
On Sep 10, 2010, at 4:13 AM, alex wrote: hello friends, as sqlite has recently introduced support for on delete/update cascade, i'd like to implement the passive_* functionality for this driver too. please give me a hint where to start. passive_delete and passive_update are database agnostic and only apply to what effects the ORM can expect from the underlying schema, just use them normally. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] IS versus = for booleans in postgresql
On Sep 10, 2010, at 11:47 AM, Jon Nelson wrote: I found something interesting recently: I have a table with a boolean column. When I wrote (low-level) sqlalchemy code, I used constructs like this: query = query.where(table.c.boolean_column==True) and when executed the query uses '='. In the psql console, however, I had been using 'boolean_column IS true', and my indexes are partial indexes which specify the same (using IS not equals). When I use ==None then I get 'IS NULL'. I'm not sure which is the totally *right* way to do this, but there is a difference. If I wanted to get IS true (or IS false) out of sqlalchemy, how would I do it? IS is important for NULL, since nothing can be equals to NULL in relational DBs. NULL = NULL returns false. IS true and IS false is not so critical, however, unless you need to compare NULL columns to false and expect to get a true value for that (which I would not recommend; I'd test for IS NULL before comparing to anything else). It could be changed by overriding the compilation for _BinaryExpression but I don't think its necessary. -- Jon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Loading attributes for Transient objects
I'm wondering if you think my use case is one you would like to support, or if you think it is sort of off on its own (I could tell I wasn't explaining our use case extremely well)... Regardless, I am setting the InstrumentedAttribute's implementation's callable_ so I have control over whether to load related objects on transient/pending objects. But the framework doesn't exactly support this in some of its assumptions about the callable_. For example, for Collections, it doesn't send passive=PASSIVE_NO_FETCH during a set() when it looks for the old value: old = self.get(state, dict_) whereas, for ScalarObjectAttributeImpl(), the set() method passes passive=PASSIVE_NO_FETCH unless active_history is True. def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF): Set a value on the given InstanceState. `initiator` is the ``InstrumentedAttribute`` that initiated the ``set()`` operation and is used to control the depth of a circular setter operation. if initiator is self: return if self.active_history: old = self.get(state, dict_) else: old = self.get(state, dict_, passive=PASSIVE_NO_FETCH) value = self.fire_replace_event(state, dict_, value, old, initiator) dict_[self.key] = value Is it appropriate to implement active_history on collections and pass passive? I can work around this somehow if you don't wish to make that change..., but let me know. On 9/8/2010 3:34 PM, Kent Bower wrote: I've got a recipe for what will work well for us. I imagine it could be useful for others, although I left out the actual serialization mechanism, since that will likely be very project specific. I'd be happy to put this on the wiki, but if you wanted to look it over first, you are more than welcome (I'd prefer your feedback). If you are busy, I can just post it and hope someone may find it useful. Thank again for your help, Kent On 9/7/2010 7:28 PM, Michael Bayer wrote: On Sep 7, 2010, at 6:41 PM, Kent Bower wrote: Two items: * How does the orm currently determine whether it is safe to try get() (e.i. there are no funny join conditions)? If you point me to the function where decision takes place, I can probably answer this myself it compares the join condition of the relationship() to that of the clause which the Mapper uses when it issues get(), then stores that away as a flag for future consultation. It's very unusual for a many-to-one relationship to be based on something other than a simple foreign-key-primary key relationship, though. * When I build up the primary key from the foreign key, is there an efficient way to build a composite key in the correct order to pass to get()? (I thought maybe synchronize_pairs, but that maybe has to do with getting the direction consistent instead?) Well if you aren't using any composite primary keys in many-to-ones, you wouldn't even have to worry about this. Otherwise, the two collections to correlate would be property.local_remote_pairs and property.mapper.primary_key. Perhaps make a dictionary out of dict([(r, l) for l, r in prop.local_remote_pairs]) and your PK value would be [getattr(instance, prop.parent.get_property_by_column(mydict[p]).key) for p in property.mapper.primary_key]. Or if you want to get ambitious you can just copy roughly whats in strategies.py on line 605 but then you're digging into internalsand looking at that now I'm wondering if strategy._equated_columns is really different than local_remote_pairs at all... Thanks again, you've been much help! On 9/7/2010 5:03 PM, Michael Bayer wrote: On Sep 7, 2010, at 4:38 PM, Kent Bower wrote: Don't want to strangle me, but when the orm (lazy)loads a MANYTONE object, it doesn't go to the database if the object is in the session. Can I get with_parent() to behave this way, or would I need to specifically build up the primary key of the related object and call query.get()? the latter. You can use get() for all many to ones if you aren't using any funny join conditions. On 9/7/2010 10:25 AM, Michael Bayer wrote: On Sep 7, 2010, at 10:12 AM, Kent Bower wrote: Mike, in your proof of concept, when __getstate__ detected transient, why did you need to make a copy of self.__dict__? self.__dict__.copy() i was modifying the __dict__ from what would be expected in a non-serialized object, so that was to leave the original object being serialized unchanged. On 9/6/2010 2:35 PM, Michael Bayer wrote: On Sep 6, 2010, at 2:11 PM, Kent Bower wrote: Also, I was hoping you would tell me whether this would be a candidate for subclassing InstrumentedAttribute? Would that make more sense or providing custom __getstate__ __setstate__ ? __getstate__ / __setstate__ are pretty much what I like to use for pickle stuff, unless some exotic situation makes me have
Re: [sqlalchemy] Re: Loading attributes for Transient objects
On Sep 10, 2010, at 12:24 PM, Kent Bower wrote: I'm wondering if you think my use case is one you would like to support, or if you think it is sort of off on its own (I could tell I wasn't explaining our use case extremely well)... Regardless, I am setting the InstrumentedAttribute's implementation's callable_ so I have control over whether to load related objects on transient/pending objects. But the framework doesn't exactly support this in some of its assumptions about the callable_. For example, for Collections, it doesn't send passive=PASSIVE_NO_FETCH during a set() when it looks for the old value: old = self.get(state, dict_) whereas, for ScalarObjectAttributeImpl(), the set() method passes passive=PASSIVE_NO_FETCH unless active_history is True. def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF): Set a value on the given InstanceState. `initiator` is the ``InstrumentedAttribute`` that initiated the ``set()`` operation and is used to control the depth of a circular setter operation. if initiator is self: return if self.active_history: old = self.get(state, dict_) else: old = self.get(state, dict_, passive=PASSIVE_NO_FETCH) value = self.fire_replace_event(state, dict_, value, old, initiator) dict_[self.key] = value Is it appropriate to implement active_history on collections and pass passive? I can work around this somehow if you don't wish to make that change..., but let me know. In your implementation of callable_, are you trying to emit change events when you set the value ? the current usage of callable_ is that the values are set in the attribute's state without triggering any change event - for collections, a method like set_committed_value() is used, which does not look at the old value - it just puts what you want right there and fires no change events. The PASSIVE_NO_FETCH in the case of the scalar object impl is an optimization, so that when you set a many-to-one attribute, there is no needless SELECT of the previous one, in those cases that we've determined don't need to do anything to the old value. This optimization doesn't apply to one-to-many or many-to-many which is why its not present in the collection version. On 9/8/2010 3:34 PM, Kent Bower wrote: I've got a recipe for what will work well for us. I imagine it could be useful for others, although I left out the actual serialization mechanism, since that will likely be very project specific. I'd be happy to put this on the wiki, but if you wanted to look it over first, you are more than welcome (I'd prefer your feedback). If you are busy, I can just post it and hope someone may find it useful. Thank again for your help, Kent On 9/7/2010 7:28 PM, Michael Bayer wrote: On Sep 7, 2010, at 6:41 PM, Kent Bower wrote: Two items: * How does the orm currently determine whether it is safe to try get() (e.i. there are no funny join conditions)? If you point me to the function where decision takes place, I can probably answer this myself it compares the join condition of the relationship() to that of the clause which the Mapper uses when it issues get(), then stores that away as a flag for future consultation. It's very unusual for a many-to-one relationship to be based on something other than a simple foreign-key-primary key relationship, though. * When I build up the primary key from the foreign key, is there an efficient way to build a composite key in the correct order to pass to get()? (I thought maybe synchronize_pairs, but that maybe has to do with getting the direction consistent instead?) Well if you aren't using any composite primary keys in many-to-ones, you wouldn't even have to worry about this. Otherwise, the two collections to correlate would be property.local_remote_pairs and property.mapper.primary_key. Perhaps make a dictionary out of dict([(r, l) for l, r in prop.local_remote_pairs]) and your PK value would be [getattr(instance, prop.parent.get_property_by_column(mydict[p]).key) for p in property.mapper.primary_key]. Or if you want to get ambitious you can just copy roughly whats in strategies.py on line 605 but then you're digging into internalsand looking at that now I'm wondering if strategy._equated_columns is really different than local_remote_pairs at all... Thanks again, you've been much help! On 9/7/2010 5:03 PM, Michael Bayer wrote: On Sep 7, 2010, at 4:38 PM, Kent Bower wrote: Don't want to strangle me, but when the orm (lazy)loads a MANYTONE object, it doesn't go to the database if the object is in the session. Can I get with_parent() to behave this way, or would I need to specifically build up the primary key of the related object
[sqlalchemy] Update a record in a table
I have some problems when I try to update information in some tables. For example, I have this table: class Channel(rdb.Model): rdb.metadata(metadata) rdb.tablename(channels) id = Column(id, Integer, primary_key=True) title = Column(title, String(100)) hash = Column(hash, String(50)) runtime = Column(runtime, Float) items = relationship(MediaItem, secondary=channel_items, order_by=MediaItem.position, backref=channels) And I have this code: def insertXML(channels, strXml): channel = Channel() session = rdb.Session() result = channel.fromXML(strXml) fillChannelTemplate(channel, channels) rChannel = session.query(Channel).get(channel.id) for chan in channels: if rChannel.id == channel.id: rChannel.runtime = channel.runtime for item in channel.items: if item.id == 0: rChannel.items.append(item) When I do rChannel.items.append(item), I got this error: FlushError: New instance Channel at 0xaf6e48c with identity key zeppelinlib.channel.ChannelTest.Channel , (152,) conflicts with persistent instance Channel at 0xac2e8ac However, this instruction is working rChannel.runtime = channel.runtime. Besides, if I try to merge, the item is getting insert in database, but the relation between channel and item is not created. I also get the same error. Any idea? 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 sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Updating a detached object
Hello guys, I have this table: class Channel(rdb.Model): rdb.metadata(metadata) rdb.tablename(channels) id = Column(id, Integer, primary_key=True) title = Column(title, String(100)) hash = Column(hash, String(50)) runtime = Column(runtime, Float) items = relationship(MediaItem, secondary=channel_items, order_by=MediaItem.position, backref=channels) I have a list of channels, but they are detached objects. I get them using joinedload option because I maniputale those objects sometimes. When I do that, I update the object. This time, I'm trying to add a new item to a detached channel object. This is the code: def insertXML(channels, strXml): Insert a new channel given XML string channel = Channel() session = rdb.Session() result = channel.fromXML(strXml) fillChannelTemplate(channel, channels) if channel.id == 0: session.add(channel) session.flush() channels.append(channel) else: for chan in channels: if chan.id == channel.id: chan.runtime = channel.runtime chan.modified = datetime.date.today() for item in channel.items: if item.id == 0: chan.items.append(item) session.merge(chan) The item is inserted in the database, but It doesn't create the relation in channel_items. Besides, I get this error: FlushError: New instance Channel at 0xb75eeec with identity key (class 'zeppelinlib.channel.ChannelTest.Channel', (152,)) conflicts with persistent instance Channel at 0xb598dec This is a problem because the need to update the channel in both sides (sever and database), so if I get the error that object is not updated in server too. Any idea? 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 sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Loading attributes for Transient objects
Sent from my iPhone On Sep 10, 2010, at 2:11 PM, Kent Bower k...@retailarchitects.com wrote: I'm headed that direction now, thanks. I didn't find anything on the wiki for how to plug in a subclassed CollectionAttributeImpl, for example. I could hack it, but is there a public or preferred way? Well this is all entirely uncharted territory. Ideally there would be solid public Apis for this stuff but especially in highly customized situations like this, they need to be specified very carefully. It seems at least that the lazy callables techniques might be further exposed. this is a lot to review, and I'll try to get to it, but since you're digging into internals anyway have you considered just creating your own AttributeImpl subclasses ? You can then implement get()/set() and make it do whatever you'd like. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Loading attributes for Transient objects
I've got a fix for our project. Python is really cool about letting you reassign methods and functions, so I just reassigned CollectionAttributeImpl._set_iterable to my own function. The point is, for my sake, don't worry about a public API, unless others also ask about it... Thanks for your help. On 9/10/2010 3:27 PM, Michael Bayer wrote: Sent from my iPhone On Sep 10, 2010, at 2:11 PM, Kent Bowerk...@retailarchitects.com wrote: I'm headed that direction now, thanks. I didn't find anything on the wiki for how to plug in a subclassed CollectionAttributeImpl, for example. I could hack it, but is there a public or preferred way? Well this is all entirely uncharted territory. Ideally there would be solid public Apis for this stuff but especially in highly customized situations like this, they need to be specified very carefully. It seems at least that the lazy callables techniques might be further exposed. this is a lot to review, and I'll try to get to it, but since you're digging into internals anyway have you considered just creating your own AttributeImpl subclasses ? You can then implement get()/set() and make it do whatever you'd like. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Loading attributes for Transient objects
I almost needed the exact same feature you have the other day.So I wouldn't close the book on it. I just know that as default behavior, or even readily switchable behavior, non-invested users get confused rather quickly. On Sep 10, 2010, at 4:21 PM, Kent Bower wrote: I've got a fix for our project. Python is really cool about letting you reassign methods and functions, so I just reassigned CollectionAttributeImpl._set_iterable to my own function. The point is, for my sake, don't worry about a public API, unless others also ask about it... Thanks for your help. On 9/10/2010 3:27 PM, Michael Bayer wrote: Sent from my iPhone On Sep 10, 2010, at 2:11 PM, Kent Bowerk...@retailarchitects.com wrote: I'm headed that direction now, thanks. I didn't find anything on the wiki for how to plug in a subclassed CollectionAttributeImpl, for example. I could hack it, but is there a public or preferred way? Well this is all entirely uncharted territory. Ideally there would be solid public Apis for this stuff but especially in highly customized situations like this, they need to be specified very carefully. It seems at least that the lazy callables techniques might be further exposed. this is a lot to review, and I'll try to get to it, but since you're digging into internals anyway have you considered just creating your own AttributeImpl subclasses ? You can then implement get()/set() and make it do whatever you'd like. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Updating a detached object
On Sep 10, 2010, at 2:57 PM, Alvaro Reinoso wrote: Hello guys, I have this table: class Channel(rdb.Model): rdb.metadata(metadata) rdb.tablename(channels) id = Column(id, Integer, primary_key=True) title = Column(title, String(100)) hash = Column(hash, String(50)) runtime = Column(runtime, Float) items = relationship(MediaItem, secondary=channel_items, order_by=MediaItem.position, backref=channels) I have a list of channels, but they are detached objects. I get them using joinedload option because I maniputale those objects sometimes. When I do that, I update the object. This time, I'm trying to add a new item to a detached channel object. This is the code: def insertXML(channels, strXml): Insert a new channel given XML string channel = Channel() session = rdb.Session() result = channel.fromXML(strXml) fillChannelTemplate(channel, channels) if channel.id == 0: session.add(channel) session.flush() channels.append(channel) else: for chan in channels: if chan.id == channel.id: chan.runtime = channel.runtime chan.modified = datetime.date.today() for item in channel.items: if item.id == 0: chan.items.append(item) session.merge(chan) The item is inserted in the database, but It doesn't create the relation in channel_items. Besides, I get this error: FlushError: New instance Channel at 0xb75eeec with identity key (class 'zeppelinlib.channel.ChannelTest.Channel', (152,)) conflicts with persistent instance Channel at 0xb598dec anytime you have that error you should be using merge() to merge state into that which is already existing, the return value from merge() is then what you need to use for your new state. I see you tried using merge earlier but your issue is not clear. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Loading attributes for Transient objects
Actually, my coworker and I were discussing, if the foreign key is specified, whether transient, pending (with autoflush off), or persistent, you intuitively *expect* that referencing the attribute will load the persistent related object. The difficultly for sqlalchemy is that you have no idea what session to pull it from. However, for many users, there is only one (Scoped)Session at a time, so there is no ambiguity. In that case, I'd argue the correct behavior is load the object/collection, if possible Thanks, it seems to be working now for me. (The other expected behavior, which I hope to tackle, is that if you change a foreign key reference and the ORM *knows* it is a foreign key reference to a loaded relation, it should expire that relation... I've asked you about that and you said it was a big undertaking... I wish I understood why better, because my plan is to implement this for my project and my hopes are that whatever has stopped you from doing so for sqlalchemy won't be an issue for our use case) On 9/10/2010 5:07 PM, Michael Bayer wrote: I almost needed the exact same feature you have the other day.So I wouldn't close the book on it. I just know that as default behavior, or even readily switchable behavior, non-invested users get confused rather quickly. On Sep 10, 2010, at 4:21 PM, Kent Bower wrote: I've got a fix for our project. Python is really cool about letting you reassign methods and functions, so I just reassigned CollectionAttributeImpl._set_iterable to my own function. The point is, for my sake, don't worry about a public API, unless others also ask about it... Thanks for your help. On 9/10/2010 3:27 PM, Michael Bayer wrote: Sent from my iPhone On Sep 10, 2010, at 2:11 PM, Kent Bowerk...@retailarchitects.com wrote: I'm headed that direction now, thanks. I didn't find anything on the wiki for how to plug in a subclassed CollectionAttributeImpl, for example. I could hack it, but is there a public or preferred way? Well this is all entirely uncharted territory. Ideally there would be solid public Apis for this stuff but especially in highly customized situations like this, they need to be specified very carefully. It seems at least that the lazy callables techniques might be further exposed. this is a lot to review, and I'll try to get to it, but since you're digging into internals anyway have you considered just creating your own AttributeImpl subclasses ? You can then implement get()/set() and make it do whatever you'd like. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.