On Fri, May 22, 2009 at 2:33 AM, Shannon -jj Behrens <[email protected]> wrote: > I have a project in production, and I decided to upgrade my app from > 0.9.6.1 to 0.9.7. I read all the docs related to upgrading. I > decided to use "paster create myapp -t pylons" to upgrade my project. > These are the headaches I encountered: > > * Warn people that if they use paster create to upgrade their project, they > probably don't want to override base.py. After all, paster create doesn't > update your controllers, and my controllers depended on the imports in > base.py. > > * AttributeError: 'module' object has no attribute 'url_for' > I was using "h.url_for" in a controller. It's even mentioned in > http://wiki.pylonshq.com/pages/viewpage.action?pageId=11174779 > (which is probably a bug). I didn't find any mention in the upgrading docs > that this was gone. I added "from routes import url_for" to my helpers.py. > > * The jsonify decorator sets the Content-Type header, but it doesn't > specify a charset. Paste freaks out if you do that. Here's what my > controller does to work around that problem: > > def _jsonify(self, s): > """This converts the jsonify decorator into a normal method. > > Sometimes a decorator isn't what I need, and treating a > function > decorator as a normal function is funky. > > HACK: The jsonify decorator sets the Content-Type header, but it > doesn't specify a charset. Paste freaks out if you do that. > > """ > ret = jsonify(lambda: s)() > response.headers['Content-Type'] = 'application/json; charset=UTF-8' > return ret > > * I updated my imports in helpers.py per the upgrading docs, but I was a bit > surprised to find out that stylesheet_link_tag was gone. It's been renamed > stylesheet_link. > > * Since I decided to keep my old base.py (since I like the automatic > imports), > I had to manually change how I imported render to > "from pylons.templating import render_mako as render". The old render > function is still available, and it's different from the new render > function. I'm guessing this isn't a big deal. > > * I had code that was setting response.status_code. It's documented here > http://wiki.pylonshq.com/pages/viewpage.action?pageId=11174779 that you > should use status_int. However, I didn't catch that and there was no > deprecation warning. Hence, my code failed silently, or rather it didn't > fail at all. It returned a 200 when I was trying to return a 400. A > deprecation warning would have been nice. > > * Once I got response.status_code working, it started shoving my HTML > response into the middle of a big error template instead of just serving > what I had. This totally messed with my Web service which counts on > the sparse HTML error messages I provide. I hacked around the problem. > In my action, I wrote: > > request.environ['error_response_is_intentional'] = True > > In error.py's document method, I wrote: > > resp = request.environ['pylons.original_response'] > if request.environ.get('error_response_is_intentional', False): > page = resp.body > else: > content = literal(resp.body) or > cgi.escape(request.GET.get('message', '')) > page = error_document_template % \ > dict(prefix=request.environ.get('SCRIPT_NAME', ''), > code=cgi.escape(request.GET.get('code', > str(resp.status_int))), > message=content) > return pag > > This is definitely a hack. I'm not even sure why this behavior changed. > If I set request.status_code, and I set the HTML containing the error > message, it should just leave it alone. > > By the way, why does the code use > request.environ.get('pylons.original_response') when it soon does > resp.body? Why not do a normal dict lookup (i.e. [])? If you don't have > that key, you'll get a None, and resp.body will crash anyway. > > Ok, I hope that was helpful. If you want bugs for any of these, I'm > happy to submit them. > > Best Regards, > -jj
This thread kind of died. I think that some of the above should result in changes to the upgrading notes, and I think one or two of them should probably result in code changes. Should I submit patches, bugs, etc.? -jj -- In this life we cannot do great things. We can only do small things with great love. -- Mother Teresa http://jjinux.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
