There’s a fairly long-standing bug in Django where initial SQL files break if they contain a double hyphen in a quoted string when you run manage.py syncdb. This bug also causes problems if you’re trying to create stored procedures in MySQL and need to change the delimiter to allow multiple statements.
Seems the problem is some overly naive code to split the SQL file into individual statements. Unfortunately there’s no easy fix without at least partially reinventing the SQL parser or spawning a separate mysql command line client process. Best approach in the meantime is to avoid using stored procedures and check any scripts that you do have using Django’s unit test framework.
A few years ago, I inherited a VB.NET application in which every method (many of which were four hundred lines long, copied and pasted all over the place, and peppered with vague sounding variable names such as blnRunIf and blnRunElse) contained this boilerplate code:
Sub MyMethod()
Try
'
' ** snip ** '
'
Catch ex As Exception
Throw New Exception ("MyClass.MyMethod::" + ex.Message)
End Try
End Sub
Those who do not understand Exception.StackTrace are doomed to reinvent it, badly.
My daily commute consists of a fifteen minute bike ride to Horsham station, fifty-five minutes on the train into London, and a twenty minute walk from London Victoria to the place where I spend most of my day staring at a computer screen before repeating the process in reverse. When you’re spending a little over three hours a day getting from A to B and back again, it’s essential to have a suitable means of humping your assorted bits and pieces around, so before I embarked on this particular adventure, I paid a visit to Millets in Horsham town centre and bought myself a rucksack that I thought would fit the bill perfectly.
At the time I thought the rear airflow system of the Berghaus Freeflow 20 rucksack was a bit of a killer feature. My old rucksack (which was ten years old and falling to bits) had been giving me a sweaty back on my bike all summer, and I figured that since my daily quota of exercise was just about to double, anything to reduce that effect would be more than welcome.
Unfortunately, this comes at a price. The struts that hold it away from your back seriously reduce the amount of space that you have at your disposal. Most of the time it isn’t too bad, but sometimes it seems very inflexible somehow. There are occasions when I want to be able to take a couple of books with me as well as a change of clothes for the journey home if the weather deems it necessary to do so, or maybe even just stop off for some shopping. Thanks to the way they curve away from your back, my Microsoft Natural 4000 keyboard almost refused to fit into it at all. Helpful, that was not.
So last week I went and bought another new rucksack. It’s a different Berghaus model, without the rigid struts this time, which makes it much more flexible, as well as giving it a a slightly higher capacity of 25 litres instead of 20. Despite the lack of air flow between it and my back, so far it hasn’t been making me sweat like crazy, but then again, I have been getting a better diet in recent months than I was a year ago, when I was having KFC for lunch almost every other day.

Posted at 08:00 on 7 May 2009.
Tagged:
commuting
MbUnit allows you to run assembly-level setup and teardown methods as part of your unit tests using the AssemblyCleanUpAttribute:
[assembly: AssemblyCleanUp(typeof(AssemblyCleaner))]
public class AssemblyCleaner
{
[SetUp]
public static void SetUp()
{
// blah
}
[TearDown]
public static void TearDown()
{
// blah
}
}
This is very useful if you want to do something like restore your database to a known configuration, perhaps incorporating all your change scripts into your unit tests. Unfortunately, there is a little gotcha. If your SetUp() method throws an exception, none of your unit tests will run, but MbUnit will still report success.
For what it’s worth, I think this is a bug, not a feature, but there is a way round it. Capture any exception, and create a unit test that re-throws it:
[assembly: AssemblyCleanUp(typeof(AssemblyCleaner))]
public class AssemblyCleaner
{
private static Exception setupException = null;
[SetUp]
public static void SetUp()
{
try {
// blah
}
catch (Exception ex) {
setupException = ex;
}
}
[TearDown]
public static void TearDown()
{
// blah
}
internal static void RethrowSetupException()
{
if (setupException != null) {
// Wrap the original exception to preserve its stack trace
throw new InvalidOperationException(
"An error occurred when setting up the tests",
setupException);
}
}
}
// You need to have your unit tests in a separate class.
// MbUnit doesn't like you including test fixtures
// in your assembly cleanup class.
[TestFixture]
public class AssemblyCleanerTest
{
[Test]
public void ReportSetupException()
{
AssemblyCleaner.RethrowSetupException()
}
}