Index: src/wp-includes/class-wp-query.php
===================================================================
--- src/wp-includes/class-wp-query.php	(revision 45284)
+++ src/wp-includes/class-wp-query.php	(working copy)
@@ -4208,6 +4208,17 @@
 		$more         = $elements['more'];
 		$numpages     = $elements['numpages'];
 
+		/**
+		 * Fires once the post data has been setup.
+		 *
+		 * @since 2.8.0
+		 * @since 4.1.0 Introduced `$this` parameter.
+		 *
+		 * @param WP_Post  $post The Post object (passed by reference).
+		 * @param WP_Query $this The current Query object (passed by reference).
+		 */
+                do_action_ref_array( 'the_post', array( &$post, &$this ) );
+
 		return true;
 	}
 
@@ -4298,17 +4309,6 @@
 			$multipage = 0;
 		}
 
-		/**
-		 * Fires once the post data has been setup.
-		 *
-		 * @since 2.8.0
-		 * @since 4.1.0 Introduced `$this` parameter.
-		 *
-		 * @param WP_Post  $post The Post object (passed by reference).
-		 * @param WP_Query $this The current Query object (passed by reference).
-		 */
-		do_action_ref_array( 'the_post', array( &$post, &$this ) );
-
 		$elements = compact( 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
 
 		return $elements;
Index: tests/phpunit/tests/query/setupPostdata.php
===================================================================
--- tests/phpunit/tests/query/setupPostdata.php	(revision 45284)
+++ tests/phpunit/tests/query/setupPostdata.php	(working copy)
@@ -416,4 +416,14 @@
 		}
 	}
 
+	public function test_the_post_action() {
+		$post = self::factory()->post->create_and_get();
+		add_action( 'the_post', function() {
+			$this->pages = $GLOBALS['pages'];
+		} );
+
+		setup_postdata( $post );
+
+		$this->assertEquals( $GLOBALS['pages'], $this->pages );
+	}
 }
