For a good example of how you can win the battle but lose the war, check out today's opinion by the Ninth Circuit.
The district court held that the City of Prescott, Arizona, had unconstitutionally impaired its contract with Pure Wafer, Inc. when it passed a certain environmental regulation. The City filed an appeal, and the Ninth Circuit agreed that there was in fact no such unconstitutional impairment.
But the Ninth Circuit went on to hold (albeit in a split opinion) that the City didn't impair the contract because it breached it instead. Which means that Pure Wafer gets pretty much identical relief, albeit on alternative grounds.
That's the problem with bad facts, sometimes. Which were here (against the City) in spades.
They'll bite you in the end.