The Magento Session object should be used when querying the current quote. Access it like so:
$checkout = Mage::getSingleton('checkout/session')
The getQuote() method is responsible for retrieving the current quote. If a quote ID doesn't exist on the session object then a new quote object (Mage_Sales_Model_Quote) is created and set up with all of the necessary data (customer id, store id, remote ip etc).
If a product has never been added to the cart or the cart isn't being loaded from a previous session, it's likely the cart will never have been saved and will have no id. The cart gets saved when a product is added from the Checkout module's CartController (Mage_Checkout_CartController) in the addAction.