That's true. But it's also true that contracts are subject to renegotiation in the case of bankruptcy. When we make financial deals we typically assume some of the risk of our financial partners.
A city certainly can, and they have, e.g. San Bernardino, Stockton, Detroit.