Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
900 stars 368 forks source link

Error messages: Updating failed. Could not update the meta value of _filled in database. #2827

Open GER32467 opened 3 months ago

GER32467 commented 3 months ago

"Updating failed. Could not update the meta value of _filled in database." Continue to receive this error when updating jobs.

masteradhoc commented 3 months ago

Hi there We have the same issue on several sites so we want to give a bigger insight on why could happen. As we see the issue can be reproduced if these two plugins are active:

As soon as a custom field is added and linked to the job posttype and an existing job gets edited this error sometimes appears image

Console Log looks like this then POST https://xxxxx/wp-json/wp/v2/job-listings/26?_locale=user 500 (Internal Server Error)

Seems like it only happens if existing jobs get edited / duplicated (f.e. over yoast duplicate post plugin). New Posts that are created are not affected. Also if fields are added over code - not acf - it works fine.

Thanks for checking this

masteradhoc commented 3 months ago

@thedebian any idea? Thanks for your help

AnthonerMonzon commented 2 months ago

@thedebian. Any idea or fix for this, I have same issue here. Thanks.

thedebian commented 2 months ago

Hi there, Would you happen to have logs of the error happening on the server by any chance? (when you see the 500 happening)

masteradhoc commented 2 months ago

@thedebian what i can see is in the server logs: Error 500 - POST /wp-json/wp/v2/job-listings/3382?_locale=user HTTP/1.0

https://eschercare.digicube.dev/wp-json/wp/v2/job-listings/3382?_locale=user

With all debug options enabled i can also see this in the console:

{
    "code": "rest_meta_database_error",
    "message": "Could not update the meta value of _filled in database.",
    "data": {
        "key": "_featured",
        "status": 500
    },
    "additional_data": [
        {
            "key": "_filled",
            "status": 500
        }
    ],
    "additional_errors": [
        {
            "code": "rest_meta_database_error",
            "message": "Could not update the meta value of _featured in database.",
            "data": {
                "key": "_featured",
                "status": 500
            },
            "additional_data": [
                {
                    "key": "_filled",
                    "status": 500
                }
            ]
        }
    ]
}
fjorgemota commented 2 months ago

I tested here and I could confirm that the issue seems to happy when a job is cloned using yoast duplicate post with a custom field added via ACF to the Jobs post type and using latest WPJM on a clean WP 6.6 site running PHP 8.3.

If you only clone a plugin without having the ACF custom field added it seems like it works fine. The same thing applies if you just have the ACF added to Job post type without cloning it. It's the combination that's breaking everything.

Checking at ACF's source code I couldn't identify anything that would conflict with WPJM, but this definitely does need more investigation to get fixed. Thanks for the report!

GER32467 commented 2 months ago

It is not just yoast duplicate post. It happens on any duplicate post plug-ins. On Jul 17, 2024, at 4:07 PM, Fernando Jorge Mota @.***> wrote: I tested here and I could confirm that the issue seems to happy when a job is cloned using yoast duplicate post with a custom field added via ACF to the Jobs post type and using latest WPJM on a clean WP 6.6 site running PHP 8.3. If you only clone a plugin without having the ACF custom field added it seems like it works fine. The same thing applies if you just have the ACF added to Job post type without cloning it. It's the combination that's breaking everything. Checking at ACF's source code I couldn't identify anything that would conflict with WPJM, but this definitely does need more investigation to get fixed. Thanks for the report!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>

masteradhoc commented 2 months ago

@fjorgemota upon further checking here is what i was able to find.

1) a job gets created, thats how the database entries look from wpjobmanager image

2) duplicate a job with yoast duplicate post - looks like this

image

So seems like entries are duplicated inside (_filled, _featured). When i try to save the job now with an ACF value set i get these errors: image

When i went ahead and deleted 513 and 514 the post was able to be updated again without an issue.

Edit: maybe a link to their developer docs where you might have the chance to influence that this doesnt get copied: https://developer.yoast.com/duplicate-post/overview/

yscik commented 2 months ago

Looks like we are calling add_post_meta with $unique = true, which exits early if the meta key already exists. So I imagine it's WPJM adding the metas first, and then the Duplicate plugins adding the meta again regardless.

We could move adding the default metas to a later hook, like wp_after_insert_post.

Right now this is called on wp_after_insert_post:

https://github.com/Automattic/WP-Job-Manager/blob/15ff6c8533b1c250dabb3c4659d5ebe56526890b/includes/class-wp-job-manager-post-types.php#L1453-L1458

And we have another one called on save_post (via job_manager_save_job_listing):

https://github.com/Automattic/WP-Job-Manager/blob/03f7745390ab31a305846dbdbb3be8b18ec49a13/includes/admin/class-wp-job-manager-writepanels.php#L673-L678

masteradhoc commented 2 months ago

@yscik sounds good! If you have a PR ready let me know please - happy to help you guys test this. What will happen to all jobs that already have these duplicate postmeta entries? anything on your side so this can be cleaned? Would be great to make sure even existing jobs work again that were duplicated once.

masteradhoc commented 2 months ago

@yscik any idea to fix this one? happy to test the PR

fjorgemota commented 2 months ago

@masteradhoc We are still thinking about how to fix this properly in WPJM. Please give us more time.

In the meantime, feel free to include both _featured and _filled as meta fields for Yoast Duplicate Post to NOT duplicate on the Settings page, in Settings -> Duplicate Post, by informing both fields in a comma separated way:

image

Regarding the already duplicated posts, feel free to delete the duplicated meta fields for each duplicated post with the lowest meta_id. Those are added by WPJM by default, before the Duplicate Post plugin adds the new meta fields with the value.

If possible, please use the "Duplicate Job" already present in the Job Dashboard (it is not available in wp-admin), it also doesn't have this issue.

I hope this helps.

masteradhoc commented 2 weeks ago

@fjorgemota any news on this? the issue still is here.

fjorgemota commented 2 weeks ago

@masteradhoc Not yet. It's on the roadmap to be worked on in the future, but we don't have any specific deadline on when this will be worked on and released to the public, especially given that technically, the workaround above should work well, and that the "Duplicate Job" feature present in the Job Dashboard doesn't have this issue.

As mentioned on the docs here: https://wpjobmanager.com/document/getting-started/adding-jobs-via-admin/

Warning! Adding jobs via the backend, wp-admin dashboard is not recommended. This is because several verification steps are not taken when adding a job this way. WP Job Manager is designed in such a way that all jobs should be submitted via the frontend job submission form.