Without having a clue or experience how it all works, you think there would be a 0.01% chance of these situations arising. A club has earmarked a player to sign, entered into talks well in advance of the window shutting and then getting the deal wrapped up, particularly in time for pre season and all the rest of it.
That video that was posted on here the other night following the Sheffield United manager around on deadline day though shows how much of a nightmare it all is, when there are essentially four parties involved in any one transfer. The buyer, seller, player and the agent.