Don’t Assume
Just fixed a bug where a query being issued from my service to Azure table storage was returning no rows. I have Cerbrata’s most excellent Cloud Storage Studio running in another window and when I issued the query in that window, it returned 14 rows. Why isn’t my app working?
After poking around and trying a couple of things, I decided to issue exactly the same query from Cloud Storage Studio as my app was issuing. To do this, I fired up Fiddler and ran the app to capture the GET request from my app; it looks like this:
(((PartitionKey eq 'WSF') and (TerminalFrom eq 'Seattle')) and
(TerminalTo eq ' Bainbridge')) and (Departure ge datetime'2010-02-07T21:23:44.093Z')
which looks like what I was issuing in Cloud Storage Studio and getting back 14 rows. Hmmm… The parentheses look a bit weird in the one being sent by my app through StorageClient; maybe that’s the problem.
But, no, it turns out that isn’t the problem. You have to look really closely at the expression to see the problem; I’ll highlight it below:
(((PartitionKey eq 'WSF') and (TerminalFrom eq 'Seattle')) and
(TerminalTo eq ' Bainbridge')) and (Departure ge datetime'2010-02-07T21:23:44.093Z')
it’s the space between the opening quote and the terminal name ‘Bainbridge’. This was caused by a typo in my code where I took a string like ‘Seattle – Bainbridge’ and split it into two pieces – a classic off-by-one error where I’m including the space in the destination terminal name.
Lesson (learned over and over): don’t test what you think and firmly believe the program is doing; test what the program is actually doing. The more you can capture the real data and real queries, the more you will be one with the program you are debugging.