Wordpress-seo: MySQL error, duplicate entry wp_yoast_seo_meta

Created on 31 Jul 2017  Â·  33Comments  Â·  Source: Yoast/wordpress-seo

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

I am seeing MySQL errors like the following turning up on some of my clients' sites:

INSERT INTO `wp_yoast_seo_meta` (`object_id`, `internal_link_count`) VALUES (6441, '3')
Duplicate entry '6441' for key 'object_id'

My first assumption was that dbDelta botched a schema update (as it often does, haha), but Yoast doesn't appear to be using that. And at any rate, the tables match the definition in admin/class-meta-storage.php.

Please describe what you expected to happen and why.

I would expect the plugin to not attempt an unconditional INSERT if the unique key already exists. Since the unique key doesn't AUTO_INCREMENT, a possible solution would be to end the query with ON DUPLICATE KEY UPDATE xxx.

How can we reproduce this behavior?

The request URI associated with all of these errors is /wp-admin/post.php, so it must be hooked into post updates. I am not a user on these sites -- I just get all the log alerts -- so am not sure if any particular steps or settings are required.

Technical info

  • WordPress version: 4.8
  • Yoast SEO version: 5.1 (free and pro)
  • Relevant plugins in case of a bug: Various (unrelated sites are affected)

Most helpful comment

@khromov I was able to reproduce this issue and I've acceptance tested the submitted pull request, which solves this issue. Therefore this issue is closed. That's the process.

The fix will be in the upcoming release (5.9). If someone experiences this issue after the release, we can decide to reopen this issue.

All 33 comments

Thanks for your bug report. We're not able to reproduce this issue, but we'll look into this.

Unless debugging is enabled, WordPress doesn't worry too much about query errors. They do, however, get tossed into the global variable $EZSQL_ERROR.

The easiest way to see what's what is to bind a shutdown function that logs the contents of this to a file. If any MySQL errors were encountered during the execution, that variable will look something like this:

$EZSQL_ERROR = array(
    array(
        'query'=>'INSERT INTO foo...',
        'error_str'=>'Duplicate entry...'
    ),
    array(
        'query'=>'Some other bad query...',
        'error_str'=>'Some other fail reason...'
    ),
);

On sites affected by this issue, it seems to happen every time a published post is updated. I assume it is connected to the link-counting feature, but am not sure if a more specific configuration cocktail is required. I am seeing this on a bunch of unrelated sites, though, so is probably not too obscure.

I can reproduce the problem in my local environment (wp 4.8.2 and only install 2 plugins: debug-bar and yoast seo).

I found yoast seo v5.6.1 and later version would show the database error message in debug-bar once I enter the add new post page of admin.

I have upgraded Yoast SEO to 5.7.1 and, every time I create a new post, I get the following error:

Query: INSERT INTO wp_yoast_seo_meta (object_id, incoming_link_count) VALUES (94296, ‘0’)

Error: Duplicate entry ‘94296’ for key ‘object_id’

Component: Plugin: wordpress-seo

I am also adding some screenshots with the details of the error. I can send you the full list of SQL queries which are performed, so that you have more details.

teknofilo - 2017-10-26 - 005

teknofilo - 2017-10-26 - 006

WordPress 4.8.2
Yoast SEO Version: 5.7.1
Every time I create a new post:

Database error: Duplicate entry '4937' for key 'object_id'
INSERT INTO wp_yoast_seo_meta (object_id, incoming_link_count)
VALUES (4937, '0')

It looks like it happens by design.

The following is from function upsert() in admin/class-database-proxy.php line 74

```/**
* Upserts data in the database.
*
* Tries to insert the data first, if this fails an update is attempted.
*
* @param array $data Data to update on the table.
* @param array $where Where condition as key => value array.
* @param null $format Optional. data prepare format.
* @param null $where_format Optional. Where prepare format.
*
* @return false|int False when the upsert request is invalid, int on number of rows changed.
*/
public function upsert( array $data, array $where, $format = null, $where_format = null ) {
$result = $this->insert( $data, $format );

    if ( false === $result ) {
        $result = $this->update( $data, $where, $format, $where_format );
    }

    return $result;
}

Not sure but would this be better?

https://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists

ex. INSERT INTO table (keys) VALUES(values) ON DUPLICATE KEY UPDATE
key1=value1, key2=value2

I have this same problem after update. It lets us publish new posts, but the Database error every time we create a new post is disconcerting. Can anyone confirm that switching back previous version helps?

image

@savy4 Switching back to 5.6.1 helps. I did that too. See my original report here: https://github.com/Yoast/wordpress-seo/issues/8158

Seeing this as well....

Downgrading to 5.6.1. fixed it for me. Thanks @savy4.

Let's hope 5.7.2 addresses/fixes the issue.

Hi guys, I have the same problem... is there any fix available?

I am also having this issue with a large multisite. I get it on any "New Post" or "New Page" screen.

We are also seeing this error.

Can anyone confirm that new update fixes?

Can anyone confirm that new update fixes?

I can confirm it does NOT fix it

Still having the same issue. NO FIX.

Is there any good choice to avoid this issue and make it upgrade at same time?

Yoast SEO 5.7.1 and older vulnerable to unauthenticated XSS
https://www.wordfence.com/blog/2017/11/vulnerabilities-yoast-seo-formidable-forms-duplicator-wordpress-plugins/

Related: https://wordpress.org/support/topic/wp_yoast_seo_meta-bug-when-adding-new-post-page/

INSERT INTO wp_yoast_seo_meta (object_id, incoming_link_count) VALUES (36726, ‘0’) /* From [domain.org/wp-admin/post-new.php?post_type=page] in [/website/wp-content/plugins/wordpress-seo/admin/class-database-proxy.php:47] */
Duplicate entry ‘36726’ for key ‘object_id’

Having the same issue for a while now.

Sorry to see 5.8 didn't fix this issue.

@andizer I think this issue should be re-opened until it's confirmed that fix actually fixes the issue (which I'm not sure it does). GitHub probably closed this issue automatically since you typed "fixed".

@khromov I was able to reproduce this issue and I've acceptance tested the submitted pull request, which solves this issue. Therefore this issue is closed. That's the process.

The fix will be in the upcoming release (5.9). If someone experiences this issue after the release, we can decide to reopen this issue.

I'm very disappointed with the plugin. INSERT INTO wp_yoast_seo_meta (object_id, incoming_link_count)
VALUES (1408, '0')
https://content.screencast.com/users/sergey_live/folders/Jing/media/f15cb9f2-184f-4906-888f-e8d642e671cd/2018-01-14_1128.png

I still experience this error as well (on different sites).

By the way, can this affect the work? Will the site fail?

@SergiiManiuk This database error does not affect any functionality.

I have the same error on my site...

Yeah. It happens on everyone's site. They programmed it that way, they like their solution, so it's not going to change. The ticket has been closed.

This issue is being addressed in https://github.com/Yoast/wordpress-seo/issues/8650

Issue still happen

Happens on Version 7.2 on Banner custom post types.

I'm having an issue where all Banners posts postmeta is being erased when any Banner edit page is opened (not even updated, merely opened) and the only db error shown shown is for wp_seo_premium.

Was this page helpful?
0 / 5 - 0 ratings