Commit 9b65627aa45 for woocommerce

commit 9b65627aa45af56a6739e82b510e737c71a5ddc4
Author: Alba Rincón <albarin@users.noreply.github.com>
Date:   Mon Jun 8 11:36:54 2026 +0200

    Fix TypeError when cached variation parent ID is returned as a string (#65496)

    * Fix TypeError when cached variation parent ID is returned as a string

    * Add changefile(s) from automation for the following project(s): woocommerce

diff --git a/plugins/woocommerce/changelog/65496-wooplug-6699-variation-parent-int-cast b/plugins/woocommerce/changelog/65496-wooplug-6699-variation-parent-int-cast
new file mode 100644
index 00000000000..350b539b581
--- /dev/null
+++ b/plugins/woocommerce/changelog/65496-wooplug-6699-variation-parent-int-cast
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix fatal TypeError in ProductVersionStringInvalidator when a persistent object cache returns the cached variation parent ID as a string.
\ No newline at end of file
diff --git a/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php b/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
index 4b7706c8117..7f13814e2b6 100644
--- a/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
+++ b/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
@@ -523,7 +523,9 @@ class ProductVersionStringInvalidator {
 		$cached    = wp_cache_get( $cache_key, 'woocommerce' );

 		if ( false !== $cached ) {
-			return $cached ? $cached : null;
+			// Cast to int: persistent object cache backends (e.g. Redis) can return scalars as strings,
+			// which would violate this method's ?int return type.
+			return $cached ? (int) $cached : null;
 		}

 		if ( $this->is_using_cpt_data_store() ) {
diff --git a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
index 840e452cbb9..c7a2e94cfea 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
@@ -976,4 +976,22 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
 		$products_list_after = $this->version_generator->get_version( 'list_products', false );
 		$this->assertNotNull( $products_list_after, 'Products list version string should NOT be deleted when variation is deleted' );
 	}
+
+	/**
+	 * @testdox Invalidating a variation does not fatal and invalidates the parent when the object cache returns the cached parent ID as a string.
+	 */
+	public function test_string_cached_parent_id_is_normalized_and_parent_invalidated(): void {
+		$variation_id = 472;
+		$parent_id    = 462;
+
+		wp_cache_set( "wc_variation_parent_{$variation_id}", (string) $parent_id, 'woocommerce' );
+		$this->version_generator->generate_version( "product_{$parent_id}" );
+
+		$this->sut->handle_woocommerce_updated_product_attribute_summary( $variation_id );
+
+		$this->assertNull(
+			$this->version_generator->get_version( "product_{$parent_id}", false ),
+			'Parent should be invalidated, proving the string parent ID was cast to int'
+		);
+	}
 }