An Experiment In Scotch

I write to discover what I believe

Month: December 2010

Route Gotchas In Pylons

I’ve been working on a Pylons app quite a bit lately and occasionally I run across issues that warrant documentation on the interwebs. That happened today concerning routes and how Pylons deals with them.

If you start getting an Import error that says “No module named content found”, you’ve run into it. According to the Pylons book, “Routes has a surprising legacy feature that means that if you don’t specify a controller and an action for a particular route, the implicit defaults of controller=’content’ and action=’index’ will be used for you”. This is certainly surprising to me and as always, things that are implicit tend to annoy me. Luckily, you can change this behavior. In your config/routing.py file, set map.explicit = True and then you’ll need to alter the route that is giving you problems to make the controller and action explicit. For example:

Before
[sourcecode language=”python”]def make_map(config):
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config[‘pylons.paths’][‘controllers’],
always_scan=config[‘debug’])
map.minimization = False
map.explicit = False

# The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved
map.connect(‘/error/{action}’, controller=’error’)
map.connect(‘/error/{action}/{id}’, controller=’error’)

# CUSTOM ROUTES HERE
map.connect(‘schedule_entry’, ‘schedule/index/{scheduleDay}’)
map.connect(‘/{controller}/{action}’)
map.connect(‘/{controller}/{action}/{id}’)

return map
[/sourcecode]

As you can see, the default behavior is for map.explicit to be set to False. The first route under CUSTOM ROUTES HERE is a named route that to my eye should match schedule up with a controller and index up with the action. Unfortunately, instead it tries to find the default implicit controller “content” which it can’t find and that throws the ImportError listed above. To fix it do this:

After
[sourcecode language=”python”]
def make_map(config):
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config[‘pylons.paths’][‘controllers’],
always_scan=config[‘debug’])
map.minimization = False
map.explicit = True

# The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved
map.connect(‘/error/{action}’, controller=’error’)
map.connect(‘/error/{action}/{id}’, controller=’error’)

# CUSTOM ROUTES HERE
map.connect(‘/schedule/index/{scheduleDay}’, controller=’schedule’, action=’index’)
map.connect(‘/{controller}/{action}’)
map.connect(‘/{controller}/{action}/{id}’)

return map
[/sourcecode]

Now the map is set to explicit and the controller and action are explicitly specified which works just fine. This all may be an artifact my novice understanding of Routes but since the book documents it this way, I guess this is the way I’m going to do it.

Thoughts On A Lecture

Last night, I attended the Jones Day lecture in the Tate series at SMU. The talk was given by Professor Joseph Stiglitz who’s CV/biography can be found here. It was an interesting talk and I thought it would be worth writing a synopsis of Professor Stiglitz’ ideas and views along with my thoughts 24 hours later.

The talk in general felt slightly rambling so I’m going to hit the points that I made notes about. He started off by discussing the causes of the financial crisis of 2008. I’m assuming there were more than one but I only wrote down the housing bubble as the main cause. One thing that he mentioned as a lost opportunity was the chance we had during and after the crash to reform our financial/banking industry. According to him, the banking industry exists to do three things: correctly allocate capital to fund economic growth, do so at a low risk to the economy as a whole and to incur a minimal cost while performing this function. Historically, this is what banks do. They loan money in an attempt to grease the wheels of capitalism by finding worthy borrowers who have both good ideas and a good ability to repay the loan.

However, the financial crash of 2008 was largely caused because the banking industry failed at all three of these functions. They grossly misallocated capital by engaging in non-traditional banking activities such as credit default swaps. They operated at an extremely high level of risk which is evident when banks began failing after the house of cards collapsed and they did all this at a very high cost which has since been passed on to the taxpayers instead of absorbed by the banks themselves. By passing up on the opportunity we had to reform our banking industry at the end of 2008 and beginning of 2009, our leaders did a terrible disservice to both the taxpayers and the economy going forward.

Professor Stiglitz spent a significant amount of his talk on unemployment and jobs. Over 40% of those who are currently unemployed have been without work for more than 6 months. Among certain worker groups, the unemployment rate is much higher. For example, while the overall unemployment rate is 9.6%, it’s 27% for teenagers, 15.7% for blacks and 12.6% for Hispanics. The unemployment rate for college graduates is also very high and this is a time when the prospects for jobs should be good, coming right out of college. He talked about how the longer a person was unemployed, the harder it was for them to get a job and that even if they did manage to find a job, the salary would likely be lower than it would have been originally. This is due to a degradation in skills and abilities over time.

He believed that the stimulus package did in fact help the economy and the unemployed. He felt that the Administration underestimated the severity of the crisis they were dealing with and did not make the package large enough. He felt that they had hoped unemployment would be around 10% without the package and 8-9% with it when in fact the crisis was much worse. He felt that without the stimulus, the unemployment rate would be around 12.5% which could easily cause a greater level of unrest in the society.

His general belief was that we are suffering from a lack of aggregate demand and that because of this lack of demand, the economic outlook was pretty grim. Lack of aggregate demand is showing up a lot lately as the reason for our current economic woes including as cited by Bill Gross of Pimco. This is of course true in a sense but not particularly helpful in my view as a way to fix the issues we face. We face a lack of aggregate demand because for the past 20 years, monetary and fiscal policy in this country has accelerated that demand into the present through the easy money policies of Alan Greenspan and the Fed. By doing so, it pushed the reckoning of that demand into the future, except that we’ve now arrived at that future. In the same way that the government tax break on buying a home pulled demand forward causing a much larger fall now, we are experiencing a lack of aggregate demand as the consumers and corporations in America now deleverage in an attempt to right the sinking ship of their personal balance sheets.

Professor Stiglitz believed that we needed more governmental stimulus to alleviate this lack of aggregate demand. Largely a Keynesian solution, he would strive to more accurately apply the stimulus to areas that would produce more good including infrastructure, education and technology. He does not believe that QE2 is going to be effective in lowering the unemployment rate because it will do little to increase demand. The reason for this is twofold though you’re only going to get the second fold because I didn’t write down the first. The second reason why it won’t help is because money always chases returns and because our economy and those of our trading partners is in the dumps, the money will have a tendency to be utilized in emerging markets where the growth is much higher and more likely to produce a return. He did feel that QE2 may increase stock prices some (Ben Bernanke will be happy to hear that since its his stated goal for QE2) but that overall, it will not be helpful in a meaningful way and could be highly detrimental to the country’s economic health over the long term.

From a monetary perspective, Professor Stiglitz feels like we are stuck. Interest rates can only go so low and even using QE2 to lower longer term rates will not appreciably increase employment which is the main issue causing the economic problems of today. He believes that fixing the economy through fiscal policy is largely a non-starter in that the current zeitgeist will prevent our politicians from using federal spending as a way to increase aggregate demand.

The effects of all this going forward are threefold (all of which I wrote down, aren’t you lucky?). First, we will have a weak economy for the foreseeable future. For Professor Stiglitz, I got the impression that foreseeable future was sometime into late 2012. The economy is largely stagnating, the unemployment rate is stubbornly remaining high and our politicians are constrained in the ways they can battle the problems. Second, the relative position of America on a global perspective will continue to decline as our power in the world lessens. This will make it hard for us to negotiate effectively. Finally, we will continue to see a more divided society from two standpoints: how we see the world and the inequality gap in income and wealth between the rich and the poor.

He believes that America does have some strengths. The main one he discussed was our secondary education system. He believes that we have a monopoly in the world on secondary education at the university level. He did not go into this in great detail but I think this is fairly well accepted.

Overall, the talk was thought-provoking and interesting. I would have liked to hear more detail regarding the viewpoint that lack of aggregate demand was causing our current growth malaise as it relates especially to the idea that our lack of growth is just the flip side of the coin of easy money policy over the past 20 years. By centering our economy on consumer spending and allowing manufacturers to offshore and outsource domestic production, I feel that a typical Keynesian solution to this abnormal recession will likely only kick the can down the road a little bit farther. Clearly, he disagreed with that thought and it would have been good to hear him talk more about his solutions. Basic Keynesian economics say that during a recession, the slowdown in spending by consumers and corporations must be offset by government spending. However, I feel like the cause of our current economic woes are the result of easy money policies already and that we will only exacerbate the problem by increasing governmental spending. On top of that, the Administration and the one before it showed precious little ability in directing the stimulus to those it would help most and instead have further empowered the financial oligarchy that largely caused the mess in the first place.

I’m sympathetic to much of Professor Stiglitz’ thoughts on the criminality of the financial oligarchy as it relates to the crash of 2008 but I’m not sure you can get from a position that easy money caused the crisis to a position of more easy money will fix it. Overall, I do agree with him that we are in for a long period of low growth and stagnation. The dollar will cease to be the reserve currency of the world, the European Union will likely face multiple sovereign defaults, large liberal states like California are likely to face great difficulty in paying their bills and our politicians are not equipped to handle these issues. All that’s a post for another time though.

Further Reading
Fiscal versus Monetary Policy
The latest employment stats