Fix a case when we should not retrieve the deployment id, also add more test coverage