Hi all,
I'm trying to track down an error where running a full TurboGears unit
test suite fails with a SQLAlchemy error, while running the single
(failing) unit test passes OK.

The SA error is of the form:
FlushError: New instance terms...@0x2b15590 with identity key (<class
'yel.model.select_source.TermSite'>, (1, 1), None) conflicts with
persistent instance terms...@0x2b8ad50

TermSite is an association table for a many-to-many relationship,
which has a multi-column primary key:
term_site_table = Table('term_site', metadata,
    Column('term_id', Integer, ForeignKey("term.id",
ondelete="CASCADE"), primary_key=True),
    Column('site_id', Integer, ForeignKey("site.id",
ondelete="CASCADE"), primary_key=True),
    Column('weight', Integer, default=1, nullable=False),
)

The error seems to signify that SA thinks there is already an object
waiting to be flushed with the same term_id and site_id. The fact that
the test only fails when a full test suite is run implies that there
is some state left over in between unit test executions.

Abbreviated setUp and tearDown methods:
    def setUp(self):
        cherrypy.root = root.Root()
        turbogears.startup.startTurboGears()
        metadata.create_all()
    def tearDown(self):
        metadata.drop_all()
        turbogears.startup.stopTurboGears()

TurboGears provides a sqlalchemy_cleanup method (here:
http://svn.turbogears.org/branches/1.0/turbogears/testutil.py), but
that seemed to be too aggressive, producing errors of the form:
InvalidRequestError: Class 'Visit' entity name 'None' has no mapper
associated with it

So:
- what is the recommended database initialisation / cleanup strategy
for unit tests involving SA?
- can anyone suggest how ORM state could be hanging around between
unit tests (I'm using an in-memory DB)?
- is there a convenient way to check on objects in the ORM, waiting to
be flushed?

This is SA 0.4.3 and TG 1.0.8 running against an in-memory sqlite DB

Thanks!
James

(Cross-posted to TG list)
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to