The root cause is probably a flush populating that pk before FA
expects it, so as a workaround you can try turning off autoflush. But
I'm not sure what would be causing a flush during sync; if you can
make a self-contained test illustrating the problem like the one
attached here http://code.google.com/p/formalchemy/issues/detail?id=21&can=1
I'd be glad to try to figure that out.
That said, here's some other improvements:
- the constructor takes the same arguments as rebind, so it's silly
to call one right after the other. just pass what you want to the
constructor.
- FA will take care of creating an empty object w/ the default
constructor to sync to, so unless you need extra args to your
constructor there's no need to manually do that
- if you're using scoped_session (and i think you are) there's no
need to pass sessions around
def create(self):
"""POST /campaigns: Create a new item."""
c.fs = FieldSet(model.Campaign, data=request.params)
if(c.fs.validate()):
c.fs.sync()
model.Session.commit()
-Jonathan