hello.

I'm trying to use DynamicMetaData so that two separate tests can each
connect to a unique db, create some tables, insert some data, delete
that data, then drop the tables.

This seems to yield ...

sqlalchemy.exceptions.ConcurrentModificationError: Updated rowcount 0
does not match number of objects updated 1

... the second time around, when trying to delete the data.  I checked
the list and FAQ and note that I am *not* trying to modify a primary
key.  This seems related to the use of DynamicMetaData and the fact
that I am creating the table then dropping it.

I was able to reproduce this scenario in a single test (below and
attached) so maybe you can see something simple I'm doing wrong?
Experimenting, I noticed that if I use two separate BoundMetaData
instances *or* switch to checkfirst=True and not drop the table then
the test works fine.  However, I don't see why this shouldn't be
possible with DynamicMetaData.  Thanks in advance.

PS. this was in sqlalchemy trunk r 2183

_

import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy.ext.sessioncontext import SessionContext
def eq_(a,b):
   assert a==b, "%s != %s" % (a,b)

meta = DynamicMetaData()

offers = Table("offers", meta,
   Column("id", INT, primary_key=True),
   Column("name", String ),
)
class Offer(object):
   pass

def db_roundtrip(dsn):
   conn = meta.connect(dsn)
   meta.engine.echo = 1

   context = SessionContext(
       lambda: sqlalchemy.create_session(bind_to=meta.engine))
   assign_mapper(context, Offer, offers)
   session = context.current

   meta.create_all()
   session.flush()

   offer = Offer()
   offer.name = 'foobar'
   session.save(offer)
   session.flush()

   rows = Offer.select()
   eq_(len(rows), 1)
   eq_(rows[0].id, 1)
   eq_(rows[0].name, 'foobar')

   session.delete(offer)
   session.flush()

   rows = Offer.select()
   eq_(len(rows), 0)

   meta.drop_all()
   session.flush()

   sqlalchemy.orm.clear_mappers()

if __name__ == '__main__':

   db_roundtrip('sqlite:///:memory:')
   # pretend this is another connection :
   db_roundtrip('sqlite:///:memory:')

   print 'OK'

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Attachment: test_sa_concurrent.py
Description: Binary data

Reply via email to