Nasty Django gotcha in my code

Posted by Ian Holsman Thu, 10 Aug 2006 03:33:00 GMT

So while trying to debug a small problem with bad urls appearing in my code and other things which looked like django or mod_python had some kind of memory leak, I stumbled onto a bug in my code.

The problem I was seeing was that on forms where I create a ‘new’ object details from the previous screen were appearing, and sometimes links were using the previous’s page url were being used instead of the current one.

So after talking to One of the Python Experts, Malcom we narrowed it down to how I was using the ‘extra_context’ parameter being passed into the request.

taking a step back for a second the ‘standard’ way most people set up their urls.py is something like


context= {
        'app':'forum',
}
and then define the URL patterns like this example…
urlpatterns += patterns('zilbo.common.tag.views.tag', 
        (r'^$', 'object_list', { 'queryset': Forum.forum_objects.all(), 
           'allow_empty':True, 
          'extra_context': context }),

)

my bug was that I didn’t realize that python passed ‘extra_context’ by reference. and I was blindly assigning things to it in the view itself. (updating the main copy). eg.. my code had something like

extra_context[‘forum’] = forum_obj

so when the next request came on the same thread it would have got a modified context dictionary (instead of the original one). and if my view didn’t actually set that variable (as was the case for the create view) it would take the old version. and would show the details as if it was an edit, not a create.

So the quick-fix in the code at the moment is to just copy() the extra_context where I modify it. and longer term is to treat it as a read-only variable.

hopefully the next djangoite with this problem will find this blog post and save themselves a few grey hairs

Posted in  | Tags ,  | 2 comments | no trackbacks

Two new chatters

Posted by Ian Holsman Fri, 04 Aug 2006 07:59:00 GMT

I’ve just launched 2 new ’’chatters’.

Med Chatter

and

Car Chatter

they follow the release of VC Chat which was soft-launched a week or two ago.

all are written in Django, and use zyons as their base.

I’ve got a couple of ideas on the boil which I will launch on those sites in about a week.. stay tuned!

Posted in  | Tags ,  | no comments | no trackbacks

Bad Cat

Posted by Ian Holsman Sun, 16 Jul 2006 22:52:00 GMT

"zyons":http://zyons.com is famous. :-) it has at least one spammer attacking it on a regular basis. "PussyCat 1.0, Murzillo compatible" is the user agent in question. my logs show that is is coming in from ~50 different IP's in the past week. I'm proud to say you wouldn't be able to tell, but I see it on the error logs, and if zyons gets more attention the spammers will adjust themselves and figure out a way to deal with it. now.. I could just ban it, but that is just making it some one elses problem as it will just jump to the next url in it's list which isn't really helping is it? So I was thinking.. there are tarpits for email, but are there tarpits for HTTP? unfortuantly I don't have a spare IP or machine/VPS to dedicate to the task, but I am willing to maintain 5-6 of them if someone will supply those. then when you get a spammy type request you can just redirect it, or make invisible forms on your pages which link to it. you could even hook it up to a RBL which black lists the IP as well. The idea behind it is to slow down the spammers and make it more expensive for them to run. Unfortuantly I can't think of a business model which will make this system self-sustaining. Anybody want to come up with some sponsorship, IP's and VPS's I can use? I think i could get a apache module going does something similar to "Spam Cannibal":http://www.spamcannibal.org/cannibal.cgi and we would then need something like dyndns to maintain a list of active tarpits. (seriously) or am I being my usual clueless self, and missing an existing implementation somewhere?

Posted in  | Tags , , , ,  | 2 comments | no trackbacks

zyons+feedjack = aggy

Posted by Ian Holsman Fri, 09 Jun 2006 03:55:00 GMT

announcing the beta of "economy-chat":http://test.economy-chat.com/aggy/ my latest "django":http://djangoproject.com mashup. It isn't finished yet (it still needs a tag-cloud, tweaking the caching, and to integrate the forum info into it) but I think it looks promising. fair warning .. it might still be a bit slow, the site is hosted in my house and caching is still a WIP. Once it becomes self-sufficent (paying for it's own hosting expenses) I'll go find a VPS or a hosting company which understands django to put it on. oh.. and thanks to "tagthe.net":http://tagthe.net for a great webservice to kickstart the tagging.

Posted in  | Tags , , ,  | 3 comments | no trackbacks

notice: my SVN area is moving

Posted by Ian Holsman Thu, 25 May 2006 20:41:00 GMT

The Fantastic folks at "Python Hosting/WebFaction":http://webfaction.com have offered to host the SVN repo for "zyons, the django forum software":http://zyons.com we've developed. Part of the deal is that we also get a "Trac instance":http://zyons.python-hosting.com I've hit a little snag, but it should repo should be available in 24-48 hours. (and I'll take the chance to re-organize things as well). the new SVN repo will be "here":http://svn.zyons.python-hosting.com/ now... to go and change all the references to it. yay.. one less thing on my home computer! The sooner I can switch that box off the quieter my life will be. update: it's there now.. update your bookmarks!

Posted in  | Tags , , ,  | 1 comment | no trackbacks

sunfirefan.com gets zyoned.

Posted by Ian Holsman Fri, 19 May 2006 21:33:00 GMT

Admittedly "SunFire":http://sunfirefan.com isn't as popular as it was when it first started, but it made the perfect candidate to get '"zyoned":http://zyons.com/forum/powered-by/sunfirefan/' The conversion was quite painless, and the old URLs still work, which I thought was important. in other Django news, "Ned Batchelder":http://www.nedbatchelder.com/blog/200605.html#e20060515T054752 announced "Tabblo":http://www.tabblo.com/ a community photo sharing site, and "Custard Melt":http://weblog.greenpeace.org/melt/archives/2006/05/back_underway.html is under active development once again.

Posted in  | Tags , , , ,  | no comments | 1 trackback

a different approach to the date based view

Posted by Ian Holsman Fri, 24 Mar 2006 22:15:00 GMT

I needed something slightly different than the generic date based views offered by Django.

I needed something which answered.. show me everything which has happened since/before X, and the standard date based view seems to be show me everything on X.

so I came up with this (Trunk Version).

The hardest part about it was getting the navigation right. as I only wanted to show a pageful at a time, and for any particular ‘time’ there might be hundreds of values.

(if someone knows of a good/better example of a UI for this please let me know and I’ll make the view do something close to that).

I plan to use this to navigate through comments on zyons which is what I have decided to call my forum project I blogged about earlier

Posted in  | Tags ,  | 2 comments | no trackbacks

Starting a new Django Project -- need volunteers

Posted by Ian Holsman Wed, 15 Feb 2006 15:56:00 GMT

Hi.

I’m starting a new application in django. community forums.

If you would like to be part of it, please feel free to subscribe to the mailing list

the code is currently sitting in my svn repo for forums.

I am opening this up in the aim to get one excellent forum application, instead of having several mediocre ones.

nothing is fixed in stone at the moment.. treat what is there as a discussion point.

Posted in  | Tags ,  | 2 comments | no trackbacks