Hmmm..hard to say. Do you have an error trace? Shouldn't matter but I would conside these changes:
targets=None to targets=[] if targets is not None: to if targets: if targets:targetsList.append(targets) to targetsList.append(targets) If you are doing "if targ:stargetsList.append(targ)", isn't "if targ" always going to be True? And the "else" clause will never run? Are the db.commits necessary?

