views:

64

answers:

2

I have been working on a website using mod_python, python, and SQL Alchemy when I ran into a strange problem: When I query the database for all of the records, it returns the correct result set; however, when I refresh the page, it returns me a result set with that same result set appended to it. I get more result sets "stacked" on top of eachother as I refresh the page more.

For example:

First page load: 10 results

Second page load: 20 results (two of each)

Third page load: 30 results (three of each)

etc...

Is this some underlying problem with mod_python? I don't recall running into this when using mod_wsgi.

A: 

Not that I've ever heard of, but it's impossible to tell without some code to look at.

Maybe you initialised your result set list as a global, or shared member, and then appended results to it when the application was called without resetting it to empty? A classic way of re-using lists accidentally is to put one in a default argument value to a function.

(The same could happen in mod_wsgi of course.)

bobince
That's a good tip, I was setting my model's "results" list to empty after the query, but I'll double-check this and make sure this isn't the case.
Dan Bair
The problem was having the query inside of the constructor of the object, by simply moving it out and storing the results in a local variable within the method solved the problem. Thanks for the help!
Dan Bair
A: 

I don't know about any of the technologies you are using. However, before you think that might be a possible bug in the packages you are using, you have to consider one thing.

Occam's razor.

Basically, "when you have two competing theories that make exactly the same predictions, the simpler one is the better."

Your two possible major theories here is that there is a bug in the components you are using (that many others use) or there is a bug in your code. Chances are (and I'm sorry) there is a bug in your code.

I use this idea with my own code and every time there was a problem it did turn out to be my code.

Hopefully others can direct you to the bug and you might want to post the problem code. You may not be clearing a result set or something -- a variable -- is being held on longer than you expect.

Frank V
Defiantly was a bug in my code :)
Dan Bair
I'm glad you solved it. :-)
Frank V