Make WordPress Core

Opened 10 years ago

Closed 18 months ago

#27424 closed defect (bug) (wontfix)

Dubious code flow in add_metadata()

Reported by: denis-de-bernardy's profile Denis-de-Bernardy Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Options, Meta APIs Keywords: close needs-patch
Focuses: Cc:

Description

The code goes:

	$result = $wpdb->insert( $table, array(
		$column => $object_id,
		'meta_key' => $meta_key,
		'meta_value' => $meta_value
	) );

	if ( ! $result )
		return false;

	$mid = (int) $wpdb->insert_id;

	wp_cache_delete($object_id, $meta_type . '_meta');

If $result up there is false, it probably means the key exists in the database. In other words, the cache is stale.

Should be:

	$result = $wpdb->insert( $table, array(
		$column => $object_id,
		'meta_key' => $meta_key,
		'meta_value' => $meta_value
	) );

	wp_cache_delete($object_id, $meta_type . '_meta');

	if ( ! $result )
		return false;

	$mid = (int) $wpdb->insert_id;

Change History (3)

#1 @nacin
10 years ago

I'm not sure. add_metadata() doesn't do any cache fetching or setting operations. The issue would be that a race between two add_metadata() calls would cause the second one to fail. At that point, the DB and cache should still be the same.

#2 @chriscct7
9 years ago

  • Keywords close needs-patch added

#3 @hellofromTonya
18 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

Thinking it's safe to close this ticket as wontfix. If it was causing a cache stale issue, I'd expect more reports and activity in this ticket. But given it's been 9 years with no activity (other than setting it to close), seems safe to close it.

However, if the issue persists today, then please reopen for further investigation.

Note: See TracTickets for help on using tickets.