Re: New SQLAlchemy tutorial

2008-03-24 Thread Wichert Akkerman

Previously Mike Orr wrote:
 I've put a new SQLAlchemy tutorial in the Pylons official docs.
 http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons

Thanks for that tutorial. I'm running into a problem with database
creation though. After following all the steps in that tutorial and
running paster setup-app it aborts with a long traceback, ending in:

  File 
/Users/wichert/Development/attingo/capos/lib/python2.4/site-packages/SQLAlchemy-0.4.3-py2.4.egg/sqlalchemy/engine/strategies.py,
 line 80, in connect
  raise exceptions.DBAPIError.instance(None, None, e)
   sqlalchemy.exceptions.OperationalError: (OperationalError) unable to open 
database file None None

tracing through load_environment the database is setup correctly:

  - init_model(engine)
  (Pdb) p engine
  
Engine(sqlite:///Users/wichert/Development/attingo/capos/capos/database.sqlite)

but it then fails on the create_all code.

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial

2008-03-24 Thread Wichert Akkerman

Previously Wichert Akkerman wrote:
 
 Previously Mike Orr wrote:
  I've put a new SQLAlchemy tutorial in the Pylons official docs.
  http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons
 
 Thanks for that tutorial. I'm running into a problem with database
 creation though. After following all the steps in that tutorial and
 running paster setup-app it aborts with a long traceback, ending in:
 
   File 
 /Users/wichert/Development/attingo/capos/lib/python2.4/site-packages/SQLAlchemy-0.4.3-py2.4.egg/sqlalchemy/engine/strategies.py,
  line 80, in connect
   raise exceptions.DBAPIError.instance(None, None, e)
sqlalchemy.exceptions.OperationalError: (OperationalError) unable to open 
 database file None None

That turned out to be my mistake: I was mixing an extra / in the
sqlalchemy.url line in my .ini file.

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial

2008-02-25 Thread askel

Mike,

Thank you for posting tips like that and keeping them up to date.
There is small typo in load_environment section -- init_model is
referred as init_engine.

I'm using little different approach. Instead of defining init_model()
and calling scoped_session() with bind parameter I simply assign
engine to bind property of MetaData instance. Creating session bound
to engine directly doesn't seem to be right way to me although it
works in cases when single engine is used and I'm not sure if it is
reliable to span session across multiply engines.  Anyway, the
following is how it looks like:

--- CUT HERE ---

-- project/model/__init__.py --
from pylons import config
from project.model.tables import *
from project.model.objects import *
from sqlalchemy.orm import mapper, scoped_session, sessionmaker

Session = scoped_session(sessionmaker(autoflush=True,
transactional=True))
mapper(Entity, entities, ...)


-- project/config/environment.py --
...
from project import model

def load_environment(global_conf, app_conf):
...
model.meta.bind = engine_from_config(config, 'sqlalchemy.')

-- project/model/tables.py --
from sqlalchemy import MetaData, Table, Column, types, ForeignKey

__all__ = ['meta', 'entities']
meta = MetaData()
entities = Table('entities', meta, ...)


-- project/model/objects.py --
class Entity(object): pass

--- CUT HERE ---

Nice side effect is that MetaData instance methods can be called
without bind parameter once it is bound to engine.

Cheers

On Feb 25, 1:20 am, Mike Orr [EMAIL PROTECTED] wrote:
 I've put a new SQLAlchemy tutorial in the Pylons official 
 docs.http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons

 It's an update of SQLAlchemy 0.4 for people in a hurry with the new
 model structure that will be in Pylons 0.9.7 (the init_model()
 function and 'meta' module).  I'll need somebody to test it,
 especially that the variable names  locations are consistent.

 Then  we'll need to update the other tutorials to match, especially
 QuickWiki and Making a Pylons Blog.  Christopher Abaid was working
 on QuickWiki, what's its status?  The blog tutorial just needs the
 model module split up. Any volunteers?

 There are a few other tutorials and FAQ items that mention SQLAlchemy.
  These need to be checked for up-to-date-ness, and anything for
 SQLAlchemy 0.3 moved to SQLAlchemy 0,3 for people in a hurry or
 deleted.

 --
 Mike Orr [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-17 Thread Alexandre CONRAD

Christoph Haas wrote:

 Would it be wise to add a model.Session.commit() to the lib/base.py -
 BaseController - __after__()?

I'm not using commit(), only flush(), so I can't really answer your 
question. But at least, __after__ would definitly be the place to put 
Session.remove() / Session.close() rather than a try: finally: block, IMHO.

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-17 Thread Michael Bayer



On Aug 17, 7:17 am, Christoph Haas [EMAIL PROTECTED] wrote:

 Does that mean I still have to run Session.commit() manually after I did
 changes? I'm glad about the autoflush option so I don't need to flush
 any more. But instead it appears I need to commit() after every change.
 Shouldn't Pylons flush the Session automatically when a request is done?
 Would it be wise to add a model.Session.commit() to the lib/base.py -
 BaseController - __after__()?

this could be done, yes.  however, for the purposes of the tutorial, i
think its better that the commit() is manual to start with, because a
commit() in all cases might be unexpected.  particularly if the
controller wishes to display an error on the page and not actually
persist changes - in that case you might not want the commit().

basically, the basic controller idea here does not address any sort of
generic way of handling success/fail conditions, like with an
exception throw or similar.  so i think commit()-in-all-cases might
assume too much, and if users want to reduce the number of explicit
commit() calls, they should choose how they want to do that.

my own preference is using a @transact decorator that inspects the
.errors attribute of the controller before committing (otherwise it
rolls back).


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Mike Orr

On 8/15/07, Jose Galvez [EMAIL PROTECTED] wrote:
 Wow a lot to digest.  I use assign_mapper which needs the
 session_context how do I get that with the the new setup?  It was pretty
 easy to get with sacontext, I'm not sure how to get at it with this new
 setup

Use Session.mapper instead of mapper.  This gives you MyClass.query
and auto-saves new instances so you don't have to call
Session.save(obj).  The query methods are on the .query property
rather than on the class itself.  The session methods are on the
Session object so they aren't repeated on the class.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Jose Galvez

Ok I think I posted to soon, I needed to read the website a little more
closely before firing off stupid questions. 
Jose

Jose Galvez wrote:
 Wow a lot to digest.  I use assign_mapper which needs the
 session_context how do I get that with the the new setup?  It was pretty
 easy to get with sacontext, I'm not sure how to get at it with this new
 setup
 Jose

 Mike Orr wrote:
   
 I've updated SQLAlchemy for people in a hurry with the new
 SQLAlchemy 0.4 programming pattern designed by Ben, MikeB, and myself.
  We're no longer using SAContext but instead putting the engine,
 metadata, and contextual session directly in our application code.
 This allows you to apply advanced concepts directly from the
 SQLAlchemy manual.

 http://wiki.pylonshq.com/display/pylonscookbook/SQLAlchemy+for+people+in+a+hurry

 SQLAlchemy 0.4 beta 2 has a new 'engine_from_config' function that
 creates an engine based on a Pylons-format configuration file.  The
 article uses this function.

 SQLAlchemy 0.4 contains many refactorings  and simplifications, and
 the manual has been rewritten to address many FAQs which have come up
 over the past several months.  This is the main reason SAContext was
 deprecated; it's not needed in 0.4.

 I'll release SAContext 0.3.5 momentarily, which is forward-compatible
 with SQLAlchemy 0.4 but keeps the existing API and uses deprecated
 SQLAlchemy features.  SAContext is now in bugfix-only mode.

 You may want to check the article again in 24 hours in case SQLAlchemy
 experts have corrected any errors.  One thing I'm adding right now is
 the pylons_scope function.

   
 

 

   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Alexandre CONRAD

Jose,

Jose Galvez wrote:

 Wow a lot to digest.  I use assign_mapper which needs the
 session_context how do I get that with the the new setup?  It was pretty
 easy to get with sacontext, I'm not sure how to get at it with this new
 setup

this could be some more ressource for you: I posted my setup, setting SA 
0.4 + Pylons 0.9.6rc2, the assign_mapper style, as I'm still using it as 
well:

http://groups.google.com/group/pylons-devel/browse_thread/thread/2b82c7093f50afc4/a6c4d7986266ddb0#a6c4d7986266ddb0

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Christoph Haas

On Wed, Aug 15, 2007 at 06:04:22PM -0700, Mike Orr wrote:
 I've updated SQLAlchemy for people in a hurry with the new
 SQLAlchemy 0.4 programming pattern designed by Ben, MikeB, and myself.
  We're no longer using SAContext but instead putting the engine,
 metadata, and contextual session directly in our application code.
 This allows you to apply advanced concepts directly from the
 SQLAlchemy manual.
 
 http://wiki.pylonshq.com/display/pylonscookbook/SQLAlchemy+for+people+in+a+hurry

Oh, well, the whole project seems to be a increasingly moving target.
First pylons.database is deprecated and replaced by SAContext. Then
SAContext is deprected. Takes some getting used to.

Rants aside. I'm converting my project to comply with the suggestions of
SQLAlchemy for people in a hurry. One typo seems to be the
sqlalchemy.default.uri and sqlalchemy.uri in the development.ini
that leads to key errors not finding the url key. Changing it to
sqlalchemy.url works better. That one was easy to find and I added a
comment to that page.

Worse is that I can't query for objects through paster shell. I get
this exception:

/home/chaas/projekte/dnsdhcp/dnsdhcp/model/__init__.py in pylons_scope()
 16 import thread
 17 from pylons import config
--- 18 return Pylons|%s|%s % (thread.id, id(config))
 19
 20 # Global session manager.  Session() returns the session object 
appropriate for the current web request.

AttributeError: 'module' object has no attribute 'id'

I'm not threading expert so I don't know where to look. In ipython the
thread module doesn't have an id.

Thanks for any hints.

 Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Michael Bayer



On Aug 16, 5:26 am, Christoph Haas [EMAIL PROTECTED] wrote:
 Worse is that I can't query for objects through paster shell. I get
 this exception:

 /home/chaas/projekte/dnsdhcp/dnsdhcp/model/__init__.py in pylons_scope()
  16 import thread
  17 from pylons import config
 --- 18 return Pylons|%s|%s % (thread.id, id(config))
  19
  20 # Global session manager.  Session() returns the session object 
 appropriate for the current web request.

 AttributeError: 'module' object has no attribute 'id'

 I'm not threading expert so I don't know where to look. In ipython the
 thread module doesn't have an id.

the proper call is thread.get_ident(), changed in r92


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Michael Bayer



On Aug 16, 5:34 am, Vegard Svanberg [EMAIL PROTECTED] wrote:
 * Christoph Haas [EMAIL PROTECTED] [2007-08-16 11:26]:

  Oh, well, the whole project seems to be a increasingly moving target.
  First pylons.database is deprecated and replaced by SAContext. Then
  SAContext is deprected. Takes some getting used to.

 Without intending to rant, I'm also a little concerned about the
 constant change of more or less fundamental parts. It seems this would
 mean that an application would have to be rewritten every so often and
 this could be quite tedious with a large and complex application, not to
 mention that everything would have to be tested and re-tested all over
 again.

 It seems to me the world is moving too fast :-)


honestly, we've tried a few things and we are watching how the
userbase responds.  Theres two things at play here :

1. SQLAlchemy 0.4 offers better configurational options than SA 0.3,
and is in the process of being released.  SAContext was designed
around 0.3 and doesn't have as strong a place with 0.4.

2. SAContext was pretty good but at the same time people put all their
faith into it as the solver-of-all-problemsand we saw a fair
amount of confusion remain.  While I liked the idea of a single
configurational object to do everything, at the same time I think
the setup works out better when the two or three individual pieces of
the configuration go where they really should go.

this latest approach is also better:

3. SA0.4 improves the user experience here a little bit by providing
more succinct objects, like Session.save instead of
sacontext.ctx.save() or whatever it was.

4. this configuration supports transactions quite nicely, and embeds
raw SQL in the same transaction smoothly.  previous patterns didnt
include any of this.

so we apologize for getting the story different a few times but im
pretty sure we'll be reaching cruising altitude very soon.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread jk

It looks like there are some issues with threading. I put the lines

try:
model.Session.configure(bind = g.sa_engine)
return WSGIController.__call__(self, environ,
start_response)
finally:
assert hasattr(model.Session, 'registry')
model.Session.remove()

...long traceback skipped...
File '***/lib/base.py', line 28 in __call__
  model.Session.remove()
File 'build/bdist.linux-i686/egg/sqlalchemy/orm/scoping.py', line 47
in remove
AttributeError: type object 'ScopedSession' has no attribute
'registry'

So it had the attribute registry right before the remove() call,
but somewhere deep inside the attribute vanished.

And, by the way, the config parameter now is not
sqlalchemy.default.uri, but is sqlalchemy.default.url (it's rather
SQLAlchemy issue). I mean, L instead of I.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Michael Bayer



 So it had the attribute registry right before the remove() call,
 but somewhere deep inside the attribute vanished.

the remove() call is actually not correct in release beta2, so ive
updated the article to reference beta3 and/or the current trunk.  also
i changed the configure call above it which was incorrect.

Wheres beta3 ?  later today :)

also added some WARNING BLEEDING EDGE caveats since this tutorial
went up *really* fast.





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Michael Bayer

ive released beta3 which fixes the remove() issue.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---




Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Jose Galvez
Well for me, I think in my production stuff I'll stick with sacontext and
sqlalchemy 3x until this sorts out a little.  Having said that I will play
with the new stuff in a separate workingenv to get a taste of how things are
going to work in the near future.

What would be really nice is if pylons had an sqlalchemy template that
added some of the code mentioned in the tutorial, maybe it could add
everything that is needed to for single default database? then all we would
have to do is edit the model, as I'm sure I'll forget one or two
configuration things and spend lots of time chasing my tail trying to figure
out why my simple query is not working :)

Jose

On 8/16/07, Michael Bayer [EMAIL PROTECTED] wrote:


 ive released beta3 which fixes the remove() issue.



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Michael Bayer

+1 on a pylons-sqlalchemy template

since if youre *really* in a hurry, thats the best


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Mike Orr

First, apologies for the mistakes in the tutorial.  I'm going to
convert my own application today, so that will be a practical test.
But I did say to check back in 24 hours in case there are corrections.
 Let's make that 48 hours from now, to take care of any remaining
beasties.

On 8/16/07, Christoph Haas [EMAIL PROTECTED] wrote:
 Oh, well, the whole project seems to be a increasingly moving target.
 First pylons.database is deprecated and replaced by SAContext. Then
 SAContext is deprected. Takes some getting used to.

Whatever's happening to the rest of the project, Pylons' relationship
to SQLAlchemy has evolved.  pylons.database built it in.  SAContext
attempted to correct some deficiencies in it.  It succeeded in some
ways but failed in others, which is why it's been retired.  Throughout
SAContext's life there has been a debate whether to include it in
Pylons. Ben wanted to get all database APIs out of Pylons core: (1) to
make it database-neutral, (2) to avoid making another bad API
decision, and (3) to avoid tying it to Pylons' release cycle which may
be too slow.  That meant SAContext needed a home.  We're considering a
Pylons extras package for things like this,which can be updated
quickly regardless of Pylons' release cycle, but so far this package
does not exist.

Then SQLAlchemy 0.4 made some standardizations and simplifications and
improved the manual, which lessened the need for SAContext.
Simultaneously I wasn't sure how to adapt SAContext to 0.4: bound
metadatas?  one global metadata?  scoped_session or custom code?
Inline BoundSessionStrategy and remove the other strategies?  Subclass
for multiple engines? Turn PylonsSAContext into a config-parsing
function?

When MikeB and Ben came up with drafts of this tutorial,and SQLAlchemy
added the engine_from_config function I'd long been lobbying for, it
was clear that this would be cleaner than shoehorning SQLAlchemy 0.4
into SAContext's arbitrary structure.  So i wanted to stop supporting
a dead-end class, provide a viable configuration that people
(including me) can use now, and get the wiki articles consistent with
each other.  Thus the quickness of getting the tutorial up, which
led to some errors creeping in.

The eventual plan is to include this in an application template so you
can do something like paster create -t pylons,sqlalchemy,genshi Foo
and get it all preconfigured.  But that will take time to verify the
right template and get it incorporated.  In the meantime people need a
viable database configuration NOW, so this is what we've got.
Improvements to the pattern will improve the eventual application
template.

 One typo seems to be the
 sqlalchemy.default.uri and sqlalchemy.uri in the development.ini
 that leads to key errors not finding the url key. Changing it to
 sqlalchemy.url works better. That one was easy to find and I added a
 comment to that page.

I checked with MikeB and he wants to stick with 'url', so I changed
the tutorial.  This means those upgrading from SAContext or
pylons.database will have to change their config key from 'uri' to
'url'.

 --- 18 return Pylons|%s|%s % (thread.id, id(config))

 AttributeError: 'module' object has no attribute 'id'

 I'm not threading expert so I don't know where to look. In ipython the
 thread module doesn't have an id.

It should have been thread.get_ident().  I misremembered the syntax.

MikeB and Ben removed the app_scope function entirely from the
article, saying it's only needed in a rare circumstance.  I re-added
it in a section at the bottom for those who need it.  You only need it
if you have multiple instances of the SAME Pylons application running
in the same WSGi process; e.g, with Paste HTTPServer 's composite.
It prevents those instances from sharing session objects.

paster shell use needs to be tested, along with standalone
applications using the model.  I believe standalone apps can just
borrow the config code in websetup.py.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Christoph Haas

On Thu, Aug 16, 2007 at 01:55:26PM -0700, Mike Orr wrote:
 First, apologies for the mistakes in the tutorial.  I'm going to
 convert my own application today, so that will be a practical test.
 But I did say to check back in 24 hours in case there are corrections.
 Let's make that 48 hours from now, to take care of any remaining
 beasties.

I should have taken that warning more seriously. :) Something made we
want to be on the bleeding edge and I wasted hours until I understood
that the in a hurry article couldn't have worked as it was. And the
link to the previous revision explaining how things are supposed to work
with SAContext was wrong. Thanks to Mike Bayer who jumped in when I
bugged him on IRC and made some quick corrections. I'm glad he works so
closely with the Pylons project so that database access is getting well
connected to Pylons.

Please don't take my posting as ranting and demanding. I appreciate the
work invested into Pylons, SQLAlchemy, Paster and SAContext. I chose to
try 0.9.6r1 then 0.9.6rc2. I wanted to be top-of-the-line with
SQLAlchemy 4.0 beta1 and beta2. Of course I would have had less trouble
if I were still using Pylons 0.9.5. I somehow thought that it might be a
nice idea to use the newer APIs already but I shouldn't be too surprised
that things are still evolving. Especially with release candidates and
beta versions.

All changes have been improvements so far. 0.9.6 is a bit clearer than
0.9.5. SQLAlchemy 0.3.9 suddenly started to make easy things easy. So I
would miss something if the API were stable but ugly. Let it evolve.

 paster shell use needs to be tested, along with standalone
 applications using the model.  I believe standalone apps can just
 borrow the config code in websetup.py.

Paster shell failed sooner today and I had to bind to an engine
manually:

model.Session.configure(bind=g.sa_engine)

After changing my model/__init__.py it works without manually binding
the engine. Thanks for the correction.

There is one problem left for me now. The code in lib/base.py doesn't seem to
do its job properly:

File '/home/chaas/projekte/dnsdhcp/dnsdhcp/lib/base.py', line 43 in __call__
  model.Session.remove()
File '/usr/lib/python2.4/site-packages/sqlalchemy/orm/scoping.py', line 47 in 
remove
  self.registry.clear()
AttributeError: type object 'ScopedSession' has no attribute 'registry'

Once that's sorted out I hope to be back on the track.

Thanks again,
 Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread Mike Orr

On 8/16/07, Christoph Haas [EMAIL PROTECTED] wrote:
 There is one problem left for me now. The code in lib/base.py doesn't seem to
 do its job properly:

 File '/home/chaas/projekte/dnsdhcp/dnsdhcp/lib/base.py', line 43 in __call__
   model.Session.remove()
 File '/usr/lib/python2.4/site-packages/sqlalchemy/orm/scoping.py', line 47 in 
 remove
   self.registry.clear()
 AttributeError: type object 'ScopedSession' has no attribute 'registry'

I don't know about that.  Somebody else got a 'registry' error too.  Mike?

model.Sesson.close() or model.Session.clear() would also be adequate,
if they work better for you.  They all discard active data, which is
what we need.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread xlyz


 update to beta3 plz
 

I'm not able to install it
it creates an empty directory

# easy_install  SQLAlchemy-0.4.0beta3.tar.gz 
Processing SQLAlchemy-0.4.0beta3.tar.gz
Running SQLAlchemy-0.4.0beta3/setup.py -q bdist_egg
--dist-dir /tmp/easy_install-99467Z/SQLAlchemy-0.4.0beta3/egg-dist-tmp-Cri_zJ
zip_safe flag not set; analyzing archive contents...
Adding SQLAlchemy 0.4.0beta3 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta3-py2.5.egg
Processing dependencies for SQLAlchemy==0.4.0beta3
Finished processing dependencies for SQLAlchemy==0.4.0beta3
# ls -R /usr/lib/python2.5/site-packages/SQLAlchemy-0.*
/usr/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta3-py2.5.egg


any suggestion?



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread xlyz

Il giorno ven, 17/08/2007 alle 01.49 +0200, xlyz ha scritto:
 
  update to beta3 plz
  
 I'm not able to install it
 it creates an empty directory
 
 /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta3-py2.5.egg
 
never mind. it's not a directory, but a zipped file

/me hides in a corner 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread xlyz


 You may want to check the article again in 24 hours in case SQLAlchemy
 experts have corrected any errors.  One thing I'm adding right now is
 the pylons_scope function.
 

I'm not an expert, but in your model you need to add:
import pylons
or you get:
type 'exceptions.NameError': name 'pylons' is not defined

and there is a typo on line 14:

-table1 = table(table1, metadata, 
+table1 = Table(table1, metadata, 

bye


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-16 Thread xlyz

Il giorno ven, 17/08/2007 alle 02.34 +0200, xlyz ha scritto:
 
  You may want to check the article again in 24 hours in case SQLAlchemy
  experts have corrected any errors.  One thing I'm adding right now is
  the pylons_scope function.
  
 
 I'm not an expert, but in your model you need to add:
 import pylons
 or you get:
 type 'exceptions.NameError': name 'pylons' is not defined
 
 and there is a typo on line 14:
 
 -table1 = table(table1, metadata, 
 +table1 = Table(table1, metadata, 
 
 bye
 

and in the relation example Address and Person class are not defined.

bye


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: New SQLAlchemy tutorial; SAContext is dead

2007-08-15 Thread Jose Galvez

Wow a lot to digest.  I use assign_mapper which needs the
session_context how do I get that with the the new setup?  It was pretty
easy to get with sacontext, I'm not sure how to get at it with this new
setup
Jose

Mike Orr wrote:
 I've updated SQLAlchemy for people in a hurry with the new
 SQLAlchemy 0.4 programming pattern designed by Ben, MikeB, and myself.
  We're no longer using SAContext but instead putting the engine,
 metadata, and contextual session directly in our application code.
 This allows you to apply advanced concepts directly from the
 SQLAlchemy manual.

 http://wiki.pylonshq.com/display/pylonscookbook/SQLAlchemy+for+people+in+a+hurry

 SQLAlchemy 0.4 beta 2 has a new 'engine_from_config' function that
 creates an engine based on a Pylons-format configuration file.  The
 article uses this function.

 SQLAlchemy 0.4 contains many refactorings  and simplifications, and
 the manual has been rewritten to address many FAQs which have come up
 over the past several months.  This is the main reason SAContext was
 deprecated; it's not needed in 0.4.

 I'll release SAContext 0.3.5 momentarily, which is forward-compatible
 with SQLAlchemy 0.4 but keeps the existing API and uses deprecated
 SQLAlchemy features.  SAContext is now in bugfix-only mode.

 You may want to check the article again in 24 hours in case SQLAlchemy
 experts have corrected any errors.  One thing I'm adding right now is
 the pylons_scope function.

   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---