OK this is http://www.sqlalchemy.org/trac/ticket/2689, one of those issues that 
as always it's super surprising hasn't been found sooner since it's pretty 
fundamental.

Your scripts will work if you ensure a dependency between the 
MenuItemMenu/MenuItemAction tables and the parent MenuItem table.  Easiest way 
is to put a ForeignKey in the primary key of each:

class MenuItemAction(MenuItem):
    __tablename__ = 'MenuItemAction'
    Id = Column(Integer, ForeignKey('MenuItem.Id'), primary_key=True)
    # ...

class MenuItemMenu(MenuItem):
    __tablename__ = 'MenuItemMenu'
    Id = Column(Integer, ForeignKey('MenuItem.Id'), primary_key=True)
    # ...

you can make either script fail about 50% of the time by randomizing the unit 
of work's internal representations using this recipe:

# put this at the top of the test script
from sqlalchemy.orm import unitofwork, session, mapper, dependency
from sqlalchemy.util import topological
from sqlalchemy.testing.util import RandomSet
topological.set = unitofwork.set = session.set = mapper.set = \
        dependency.set = RandomSet





On Apr 1, 2013, at 10:39 AM, Michael Bayer <mike...@zzzcomputing.com> wrote:

> test.py doesnt fail for me, test1.py does.   not sure whats going on with it 
> yet, will know today
> 
> 
> On Apr 1, 2013, at 9:11 AM, gvv <gvver...@gmail.com> wrote:
> 
>> Hi All,
>> 
>> I am using 0.7.10, sqlite memory and decl_enum.py from 
>> http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
>> for testing.
>> 
>> Scenario 1 - test.py
>> I am running it 8 times, 7 out of 8 it works and I get the following output:
>> 0.7.10
>> 1 10 Action Main /gvv
>> 2 20 Action Main /gvv1
>> 3 30 Menu Main Sys
>> 4 10 Action Test test
>> 
>> 1 out of 8 I get the following error:
>> sqlalchemy.exc.IntegrityError: (IntegrityError) PRIMARY KEY must be unique 
>> u'INSERT INTO "MenuItem" ("Id", "TypeOfMenuItem", "ItemMenu_Id", "Line", 
>> "Desc", "CreateTimeStamp", "CreateOpId_Id", "ModifiedTimeStamp", 
>> "ModifiedOpId_Id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' ((1, 'Action', 1, 10, 
>> 'Action 1', '2013-04-01 23:57:56.664654', 1, None, None), (2, 'Action', 1, 
>> 20, 'Action 2', '2013-04-01 23:57:56.664667', 1, None, None), (1, 'Menu', 1, 
>> 30, 'Menu', '2013-04-01 23:57:56.664674', 1, None, None))
>>  
>> Scenario 2 - test1.py
>> I have included table ProductClass just for noise. In scenario 1 it works
>> Adding index=True to ProductClass.Class:
>> Class = Column(String(16), index=True, nullable=False)
>> always gives me the following error:
>> sqlalchemy.exc.IntegrityError: (IntegrityError) PRIMARY KEY must be unique 
>> u'INSERT INTO "MenuItem" ("Id", "TypeOfMenuItem", "ItemMenu_Id", "Line", 
>> "Desc", "CreateTimeStamp", "CreateOpId_Id", "ModifiedTimeStamp", 
>> "ModifiedOpId_Id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' (1, 'Menu', 1, 30, 
>> 'Menu', '2013-04-02 00:05:20.569187', 1, None, None)
>> 
>> What am I doing wrong?
>> 
>> Thank you in advance for your help.
>> 
>> 
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>> <decl_enum.py><test.py><test1.py>
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to