> >
> > Yes, the seed class makes new objects that I want in the db as
> > fixture. I want to use the class as a namespace for a standard set of
> > fixture objects, mostly because of the ease of setting it up that
> > gives me, and because I can do things like make variants of the
> > standard fixture with a simple inherit and override. Of course the
> > class code gets run at import time of the class, so the objects in the
> > seed class are created then, with the active scoped session. However,
> > I want to reuse that fixture declaration over and over again, with a
> > fresh session and fresh tables. So when the tests start, the seed
> > class has created objects in the session imported from turbogears.
> > This session doesn't get flushed. The first test recreates the tables,
> > copies the seed objects into the new session for the first test,
> > flushes it to the db, does it's test stuff, and then wipes out that
> > session. Then I hit the snag because I can't recopy these objects into
> > another session after they have been persisted and I'd like to repeat
> > that process:
> > - drop tables
> > - make new session
> > - copy fixture objects into the new session
> > - flush to db
> > - do tests
> >
> > I guess I need to either:
> > - wipe out the SQLA knowledget that they have been persisted
> > or
> > - clone the seed objects some how so I have new ones for each session
> 
> I think the best way is to create a function that gives you new objects,
> and is loaded in during the setup() for your tests.  its the same amount
> of typing as declaring them module-wide.    the second way is to clone the
> objects or create them from some kind of state, like dicts.   the third,
> merge() them into the session - the original objects will be unchanged. 
> fourth, and this is the most hacky way of all, "from sqlalchemy.orm import
> attributes;  del attributes.instance_state(instance).key".   you'd have to
> do that on all objects in the whole graph which you want to reuse.   i
> don't see that as being any easier than just cloning them.

Hi Mike, I tried out the merging, but am hitting the snag that objects
referred to in relations are now going into the db twice. Ie

class MySeedData(SeedData):
  van = Region(name="Vancouver")
  event_1 = Event(name="Event 1", region=van)

is putting the Region in twice.


I also tried out the instance clearing tip. I'm on sa 0.4.8, but there
is no orm.attributes.instance_key. There is attributes.InstanceKey, but
if use that to create an object, the object created doesn't have an
attribute named 'key' either. I'd still like to try out the instance
clearing method if you any suggestions for 0.4.8

Thanks
Iain
  
> 
> > 


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