when i run this program, I get no errors.

a few things to note:

it makes no sense to do a session.flush() after youve dropped the table (similarly, it makes no sense to flush() before youve done anything but thats less of an issue). if there were any modified state within your session to actually be flushed, the operation would fail since the table is dropped (but in this test, theres no changes to flush at that point, so no error occurs).

running the same test twice with two separate instances of "sqlite:// memory" will produce no continuity between the two databases, since sqlite://memory databases are completely unique per connection. but again, in this test youre doing a completely new and unrelated set of operations on each connection, so no error occurs.

wild guess, that the test you have which fails is switching between "sqlite://memory" databases within a single ORM session, so the update of a row saved within the first sqlite://memory database produces no changes within the second sqlite://memory database since its a completely new database (but then, youd also have to get the table creates in there too, so still not exactly sure what the conditions are on your end).

in any case, viewing SQL output should reveal exactly whats going on.


On Jan 6, 2007, at 6:54 PM, Kumar McMillan wrote:

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'

>
<test_sa_concurrent.py>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to