On Oct 1, 7:53 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> On Tue, Sep 30, 2008 at 7:55 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > Hello, I've been trudging through various tutorials and documentation
> > trying to get TG 1.1b1 working.
>
> maybe you will want to try the 1.0 branch as it's well documented 1.1
> had a lot of changes and it isn't really ready for first timers.

Thanks, but I'm required to use the beta version.  The prospective
employers wanted applicants to struggle with a new app.


> > None of them really give me all the
> > answers I need.  The SA documentation either gives the declarative
> > style (0.5) docs, or the non-declarative style(0.4) docs.  Since the
> > 0.5 docs don't show how to use relations in the old style,
>
> umm interesting. for what is worth they are identical except that in
> declarative you don't use the first argument (Class Name) that you
> will use in "classical".

That's nice to know.  Thanks.


> > I've had to
> > learn from the 0.4 docs.  The problem is, the SA 0.4 docs constantly
> > refer to various session manipulations (session.query in particular);
> > but none of the turbogears docs I've come accross mention anything
> > about using session objects/methods.
>
> Did you saw this page?http://docs.turbogears.org/1.0/SQLAlchemy

I just ran accross it before reading your post.  It does answer my
session questions, assuming 1.1 is designed the same as 1.0...


> Basically TG controllers wrap everything in a transaction which means
> you don't normally have to call anything session related.
>
> > All I know is that when using
> > the tg-admin shell, session changes are automatically queued up and
> > committed when the shell is exited. or when executing
> > session.comitt().  This is an undesirable, feature by the way, since I
> > can't specify which new object instances to save and which to throw
> > away; or at least I don't know how to do so.
>
> No this isn't undesirable, that is why it is a session, you may be
> confusing the term with an http session, while it is actually a db
> session.http://www.sqlalchemy.org/docs/04/session.html#unitofwork_what
>
> if you want to get rid of some object you created (maybe by mistake)
> you could run del obj in that python shell and it will be discarded.

I've read the above document also, but both documents are inconsistent
with what I'm seeing in tg-admin shell.  Maybe the controllers module
is handled differently than tg-admin shell?  Here's a couple examples
of what I'm talking about.  Within tg-admin shell:

In [1]: for group in Group.query.all(): print group.group_name
   ...:
admin
Blah
one

In [2]: g = Group(group_name=u'two', display_name=u'group two')

# Now I decide I don't want g to be commited to the database; but i do
want all previous modifications to be saved; so I try del

In [3]: del g

In [4]: session.commit()
---------------------------------------------------------------------------
InvalidRequestError                       Traceback (most recent call
last)

/home/ce/smplab/<ipython console> in <module>()

/usr/lib64/python2.5/site-packages/SQLAlchemy-0.5.0rc1-py2.5.egg/
sqlalchemy/orm/scoping.py in do(self, *args, **kwargs)
    104 def instrument(name):
    105     def do(self, *args, **kwargs):
--> 106         return getattr(self.registry(), name)(*args, **kwargs)
    107     return do
    108 for meth in Session.public_methods:

/usr/lib64/python2.5/site-packages/SQLAlchemy-0.5.0rc1-py2.5.egg/
sqlalchemy/orm/session.py in commit(self)
    665                 self.begin()
    666             else:
--> 667                 raise sa_exc.InvalidRequestError("No
transaction is begun.")
    668
    669         self.transaction.commit()
No transaction is begun
InvalidRequestError: No transaction is begun.

# There's actually two problems here:  1) this "No transaction is
begun" error above happens no matter what I try to commit.  2) After
exiting the shell, as below, and answering "yes" (which I assume does
a commit), the new group still appears in the database as follows:

In [5]: Do you wish to commit your database changes? [yes]

In [1]: for group in Group.query.all(): print group.group_name
   ...:
admin
Blah
one
two

So, both del and commit don't seem to be working.

Also, even if they did work for me, why do the examples show a new
object being saved and then commited?  Doesn't commit call a flush,
which saves all objects, so that the first save is redundant?

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