I have the exact same problem with Elixir + sqlalchemy.  :-(

On Feb 14, 3:05 pm, lorax <[EMAIL PROTECTED]> wrote:
> Ok a few people have recommended that I go with Elixir now, so I'm
> going to give that a shot.  I hope it works because I really want TG
> to work out for me!
>
> On Feb 14, 9:36 am, lorax <[EMAIL PROTECTED]> wrote:
>
> > Ok I'm starting to wonder if I've found a bug in Turbogears and/or
> > sqlalchemy.  I decided to start with a fresh project and add only the
> > required pieces so I could test this.  I'm still getting an error when
> > I execute session.flush().
>
> > I started with the following:
> > tg-admin quickstart --sqlalchemy -t tgbig snifflemap
>
> > Then I added a 'widgets' folder with login_widgets.py containing the
> > following:
>
> > from turbogears import widgets,validators
>
> > class registrationFields(widgets.WidgetsList):
> >     user_id = widgets.TextField('user_id', label="User ID")
> >     password = widgets.PasswordField('password', label="Password")
> >     password_verify = widgets.PasswordField('password_verify',
> > label="Verify Password")
> >     first_name = widgets.TextField('first_name', label="First Name")
> >     last_name = widgets.TextField('last_name', label="Last Name")
> >     email = widgets.TextField('email', label="Email Address")
>
> > class registrationFormSchema(validators.Schema):
> >     user_id = validators.UnicodeString(not_empty=True)
> >     password = validators.UnicodeString(not_empty=True)
> >     password_verify = validators.UnicodeString(not_empty=True)
> >     first_name = validators.UnicodeString(not_empty=True)
> >     last_name = validators.UnicodeString(not_empty=True)
> >     email = validators.Email(not_empty=True)
> >     chained_validators = [
> >         validators.FieldsMatch('password','password_verify')
> >     ]
>
> > registration_form = widgets.TableForm(
> >     fields=registrationFields(),
> >     action="process_registration",
> >     validator=registrationFormSchema()
> > )
>
> > I added a register.kid to templates, containing:
>
> > <body>
> >     <div id="content">
> >     ${form.display()}
> >     </div>
> > </body>
>
> > Finally, to root.py I added a couple imports and registration
> > functions:
>
> > from snifflemap.widgets import login_widgets
> > from snifflemap.model import User
> > from turbogears.database import session
>
> >     @expose(template="snifflemap.templates.register")
> >     def register(self):
> >         return (dict(form=login_widgets.registration_form))
>
> >     @expose()
> >     def process_registration(self, **data):
> >         user=User()
> >         user.user_name = data['user_id']
> >         user.email_address = data['email']
> >         user.password = data['password']
> >         session.save(user)
> >         try:
> >            session.flush()
> >         except:
> >            flash('There was an error!')
> >         raise redirect('/')
>
> > When I include the flush as above, I get the following error in my
> > browser:
> > File "c:\python25\lib\site-packages\sqlalchemy-0.4.2p3-py2.5.egg
> > \sqlalchemy\orm\session.py", line 489, in commit
> >     raise exceptions.InvalidRequestError("No transaction is begun.")
> > InvalidRequestError: No transaction is begun
>
> > If I do not include the flush, I cannot trap the exception
> > (IntegrityError) which occurs after I duplicate a user record.
>
> > Is this a bug?
>
> > On Feb 13, 8:39 pm, lorax <[EMAIL PROTECTED]> wrote:
>
> > > I converted my tables to innodb and no luck.  I still miss the
> > > exception without the session.flush() and get a 'no open transaction'
> > > error if I add the session.flush().
>
> > > On Feb 13, 1:20 pm, lorax <[EMAIL PROTECTED]> wrote:
>
> > > > I'm having trouble trapping an IntegrityError with sqlalchemy.  I have
> > > > the following:
>
> > > > from turbogears.database import session
> > > > from myproject.model import User
>
> > > > user = User()
> > > > user.user_name = "Harry"
> > > > user.password = "mypass"
>
> > > > try:
> > > >     session.save(user)
> > > > except:
> > > >     flash("Duplicate entry!")
> > > >     raise redirect ("register")
>
> > > > ..but it doesn't catch the error and it comes back to me in the
> > > > browser.  I tried adding a session.flush() in the try block but there
> > > > is an error about no transaction being created.  I'm assuming that is
> > > > because I'm using mysql myISAM
>
> > > > Can anyone help?  Thanks so much.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to