[sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
I've met so few other Farrells, maybe we ARE related!! Get it, related, in a SqlAlchemy group. Oh man I'm such a geek!! -Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Bob Sent: Tuesday, December 02, 2008 9:00 AM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat I keep thinking one of my relatives has emailed me when you post here and I get all excited. Any chance you can change your name ? :-) 2008/12/2 Doug Farrell [EMAIL PROTECTED]: Michael, Thanks for the pointer, that makes great sense, and once again points how my generally small database design skills. I'll update my code to try this out. Again, Thanks! Doug From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bayer Sent: Saturday, November 29, 2008 9:28 PM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat Simon's suggestion about the duplicate name still holds. Your relation from Stat-ExtraStat currently needs to be one-to-one since you cannot have more than one ExtraStat referencing a single Stat, due to the PK constraint on ExtraStat.name. The error is raising at the point of query() since autoflush is kicking in - use session.flush() to isolate the error. On Nov 29, 2008, at 12:18 PM, Doug Farrell wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug r 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 sqlalchemy
[sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
Michael, Thanks for the pointer, that makes great sense, and once again points how my generally small database design skills. I'll update my code to try this out. Again, Thanks! Doug From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bayer Sent: Saturday, November 29, 2008 9:28 PM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat Simon's suggestion about the duplicate name still holds. Your relation from Stat-ExtraStat currently needs to be one-to-one since you cannot have more than one ExtraStat referencing a single Stat, due to the PK constraint on ExtraStat.name. The error is raising at the point of query() since autoflush is kicking in - use session.flush() to isolate the error. On Nov 29, 2008, at 12:18 PM, Doug Farrell wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
I keep thinking one of my relatives has emailed me when you post here and I get all excited. Any chance you can change your name ? :-) 2008/12/2 Doug Farrell [EMAIL PROTECTED]: Michael, Thanks for the pointer, that makes great sense, and once again points how my generally small database design skills. I'll update my code to try this out. Again, Thanks! Doug From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bayer Sent: Saturday, November 29, 2008 9:28 PM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat Simon's suggestion about the duplicate name still holds. Your relation from Stat-ExtraStat currently needs to be one-to-one since you cannot have more than one ExtraStat referencing a single Stat, due to the PK constraint on ExtraStat.name. The error is raising at the point of query() since autoflush is kicking in - use session.flush() to isolate the error. On Nov 29, 2008, at 12:18 PM, Doug Farrell wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
Sorry, I didn't realize I had done that, I thought I had started a new post. My apologies. -Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, November 28, 2008 11:45 PM To: sqlalchemy Subject: [sqlalchemy] Re: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat What was your justification of changing the name of my thread to a completely different topic instead of starting a new thread? I don't think thats good etiquette. On Nov 29, 5:22 am, Doug Farrell [EMAIL PROTECTED] wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
Simon's suggestion about the duplicate name still holds. Your relation from Stat-ExtraStat currently needs to be one-to-one since you cannot have more than one ExtraStat referencing a single Stat, due to the PK constraint on ExtraStat.name. The error is raising at the point of query() since autoflush is kicking in - use session.flush() to isolate the error. On Nov 29, 2008, at 12:18 PM, Doug Farrell wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/ tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Doug Farrell Sent: 28 November 2008 18:22 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug This may not be the cause of your problem, but with your mapping above, I think you can only have one ExtraStat per Stat, because they have the same primary key (the 'name' column). If 'name' is the only thing that uniquely distinguishes an ExtraStat, you can only have one per name. 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 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
What was your justification of changing the name of my thread to a completely different topic instead of starting a new thread? I don't think thats good etiquette. On Nov 29, 5:22 am, Doug Farrell [EMAIL PROTECTED] wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat
What was your justification of changing the name of my thread to a completely different topic instead of starting a new thread? I don't think thats good etiquette. On Nov 29, 5:22 am, Doug Farrell [EMAIL PROTECTED] wrote: Hi all, I'm having a problem with a new instance of a relation conflicting with an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my simplified classes: class Stat(sqladb.Base): __tablename__ = stats name = Column(String(32), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) extraStats = relation(ExtraStat, backref=stat) class ExtraStat(sqladb.Base): __tablename__ = extrastats name = Column(String(32), ForeignKey(stats.name), primary_key=True) total= Column(Integer) created = Column(DateTime, default=datetime.datetime.now()) updated = Column(DateTime) states = Column(PickleType, default={}) The above Stat class has a one-to-many relationship with the ExtraStat class (which I think I've implemented correctly). Later in the program I create an in memory data model that has as part of it's components two dictionaries that contain Stat instances. Those Stat instances have relationships to ExtraStat instances. My problem comes in the following when I'm trying to update the data in those instances/tables. Here is a section of code that throws the exception: pressName = press%s % pressNum # add new ExtraStat instances as relations self._addProductStatsPress(productType, pressName) self._addPressStatsProduct(pressName, productType) try: extraStat = session.query(Stat). \ filter(Stat.name==productType). \ join(extraStats). \ filter(ExtraStat.name==pressName).one() except: extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE) self.productStats[productType].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now extraStat = session.merge(extraStat) try: extraStat = session.query(Stat). \ filter(Stat.name==pressName). \ join(extraStats). \ filter(ExtraStat.name==productType).one() throws exception right here except: extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE) self.pressStats[pressName].extraStats.append(extraStat) extraStat.states.setdefault(sstate, 0) extraStat.states[sstate] += 1 extraStat.updated = now The marked area is wear it throws the exception. I'm not sure what to do here to get past this, any help or ideas would be greatly appreciated. The exact exception is as follows: Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent instance [EMAIL PROTECTED] Thanks! Doug --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---