Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 15180)
+++ wp-includes/post.php	(working copy)
@@ -369,10 +369,13 @@
 		wp_cache_add($post->ID, $_post, 'posts');
 	} else {
 		if ( is_object($post) )
-			$post = $post->ID;
-		$post = (int) $post;
-		if ( ! $_post = wp_cache_get($post, 'posts') ) {
-			$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
+			$post_id = $post->ID;
+		else
+			$post_id = $post;
+
+		$post_id = (int) $post_id;
+		if ( ! $_post = wp_cache_get($post_id, 'posts') ) {
+			$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
 			if ( ! $_post )
 				return $null;
 			_get_post_ancestors($_post);
