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.