On Tue, Jan 31, 2012 at 3:30 AM, Tom Lazar <[email protected]> wrote:
> i really would like to have a clean, convenient and supported way to access
> global settings. i guess, the answer is that pyramid currently doesn't have
> this on offer.
>
> generically exposing the settings that were used to invoke a pyramid instance
> on module level would be nice, but i infer from what you've said the the
> convenience that would add would be outweighed by the stuff that could
> possibly go wrong. correct?
Pylons had magic globals ('config' -- akin to settings, 'request',
'response', 'session', etc), and they failed in situations like unit
tests or maintenance utilities where you're not in a view called by
the router. Plus they're always a source of potential failure and
hard-to-trace bugs even when they do work most of the time. In short,
it's harder to *guarantee* your application will always be correct
when you're not passing the objects as arguments through to all the
routines that need them. If you pass them all the way through or
attach them to 'self', it leaves a visible trace of how the object got
from one place to another, and who's responsible for modifying it.
With magic globals, this is taken out of your control and you have to
depend on black-box code in the framework, which is harder to test and
guarantee.
A major goal for Pylons 2 was to eliminate the magic globals. Pylons
merged into Pyramid because it fulfilled that goal.
> maybe i could just mock get_current_registry() in my test harness and simply
> use that in the few places of my code that does not have convenient access to
> a request.
That's the back door. The 'threadlocals' module gives you the state
objects when you can't access them any other way; e.g., in 'pshell'.
But as the manual says, you should try to use it as little as
possible, because it is essentially a magic global.
--
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 [email protected].
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.