Monday, December 31, 2007

When debugging, watch your watches

I should know better.

We had a section of code where a new 'document' was created in our web app. A document in this app consists of data in various tables. So, what happens is, we start adding rows to the tables in the dataset, but before we add any rows, we turn off EnforceConstraints for the dataset.

Later, right before we Save the dataset, we run a method, IsValid, which turns EnforceConstraints back on, and checks the dataset's HasErrors.

So, our flow works like this:

  EnforceConstraints = False
  ... add a bunch of rows, which may at times have Nulls where their shouldn't be.
  ... Nulls get filled in.
    EnforceConstraints = True
    ... If HasErrors, throw exception.
End Method

Now, what would happen if you put IsValid in the Watch window? That's right, EnforceConstraints would be set to True very frequently.

I'll go bandage the hole in my foot now.

No comments: