The seller can file a Chapter 7 bankruptcy even if he is in contract to sell. The contract to sell (purchase contract) is an executory contract and the bankruptcy trustee has 60 days to accept or reject it. However, in the vast majority of cases, the property is upside down and the trustee will therefore have no interest in accepting the contract, so it will automatically be rejected after 60 days. If that happens, the purchase agreement will be unenforceable. (11 U.S.C. Section 365(d)(1).)
One exception to this occurs if the buyer is in contract to purchase and has actually taken possession of the property prior to the seller filing bankruptcy, then the buyer can sue for specific performance (11 U.S.C. Section 365(i)).