pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 265 forks source link

Removing relationship in WP doesn't wipe data in database #5858

Open TrevorSqE opened 4 years ago

TrevorSqE commented 4 years ago

Issue Overview

Relationships are getting 'stuck' - data seems to be deleted in one direction but not the other. It's possible that an incomplete data import was at fault in the first place (?), but we can't fix things manually.

Expected Behavior

Untagging people when editing the sector's relationship field should flush them both ways from the database.

Current Behavior

We have a site with a bi-directional relationship field connecting CPTs 'person' and 'sector'. On a front-end display page for a sector (ID 1234, say), I can see 4 tagged people, but only 2 in the relationship field if I edit the page. If I untag one of those people and save, I now see only 1 in the back-end, but still see 4 on the front.

If I look in the database, wp_postmeta), I see one record with post_id 1234 and meta_key 'related_persons'. But I see four records with meta_value 1234 and meta_key 'related_sectors'.

If I go to edit the people instead of the sectors, I don't see the sector tagged, so can't try deleting it there.

Steps to Reproduce (for bugs)

I can share a login if helpful.

Possible Solution

Make sure that untagging deletes relationship field data from both ends, not just one?

WordPress Environment

``` WordPress Version: 5.5.1 PHP Version: 7.3.1 MySQL Version: 5.5.5 Server Software: Apache/2.4.37 (Unix) OpenSSL/1.0.2q PHP/7.3.1 mod_perl/2.0.8-dev Perl/v5.16.3 Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36 Session Save Path: /Applications/XAMPP/xamppfiles/temp/ Session Save Path Exists: Yes Session Save Path Writeable: Yes Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: No Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: wp_ WP Multisite Mode: No WP Memory Limit: 40M Current Memory Usage: 81.503M Current Memory Usage (real): 7.000M Pods Network-Wide Activated: No Pods Install Location: /Users/trevor/Sites/bovill2020.dev.cc/wp-content/plugins/pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: Bovill Currently Active Plugins: Admin Columns Pro: 5.3.2 Admin Columns Pro - Advanced Custom Fields (ACF): 2.6.3 Admin Columns Pro - Pods: 1.5.1 Admin Menu Editor Pro: 1.83 Advanced Custom Fields PRO: 5.9.1 Advanced Editor Tools (previously TinyMCE Advanced): 5.5.1 All-in-One WP Migration: 7.28 All-in-One WP Migration Unlimited Extension: 2.37 Breadcrumb NavXT: 6.5.0 Classic Editor: 1.6 Events Manager: 5.9.8.1 Gravity Forms: 2.4.21 Intuitive Custom Post Order: 3.1.2 MalCare Security - Free Malware Scanner, Protection & Security for WordPress: 4.35 ManageWP - Worker: 4.9.7 Pods - Custom Content Types and Fields: 2.7.22 Quick Bulk Post & Page Creator: 1.0.4 Regenerate Thumbnails: 3.1.3 Simple History: 2.37.2 WordPress Importer: 0.7 WP All Import Pro: 4.6.4 WP Migrate DB Pro: 1.9.13 WP Migrate DB Pro Media Files: 1.4.15 WP Migrate DB Pro Theme & Plugin Files: 1.0.5 ```

Pods Package Export (helpful!)

[pods.export.txt](https://github.com/pods-framework/pods/files/5403954/pods.export.txt)

Workaround or Alternate Solution Until Bug is Addressed

Related Issues and/or PRs

We've seen this before and, I think, reported it but I can't seem to find past issues in my name. Sorry if I'm duplicating!

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label Type: Bug to this issue, with a confidence of 0.85. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

quasel commented 4 years ago

Hi,

the Reason it works in the backend is wp_podsrel https://pods.io/docs/database-reference/database-storage-relationship-fields/ Did you use the default edit screen to change the relationship or are you using any other way?

Are you using pods to output the data in the frontend? Does it happen to any other pod relationship you have setup?

TrevorSqE commented 4 years ago

Thanks Quasel!

TrevorSqE commented 4 years ago

PS Just had the same issue reported by a different client, different site, different CPTs. In their case they were unable to remove tagged items (of post type A) from an item of post type B; but on testing, if I went to edit an item of post type A, tagged item B there and then removed it again, that managed to flush it out - but obviously a bit of a clunky method.

quasel commented 3 years ago

that's weird- @JoryHogeveen did you see anything in that direction?

JoryHogeveen commented 3 years ago

@quasel I already spoke with @TrevorSqE on Slack. This might be an Admin Columns inline edit related issue. He will do some tests on a sandbox and report back to me!

quasel commented 3 years ago

Okay as I run into this issue again I can confirm that's a bug with bi-directional relationships!

Relationship information ist stored in multiple places (details see below) If you remove an item on one side it should be removing itself from both sides but removal only works properly for the podsrel table. Seems Admin Columns uses the Information from the meta storage for the table view, inline editing works but leads to same issue with meta storage.

meta storage information for the related item is not updated if you

@sc0ttkclark so if it's not, it should be considered a bug and we should get a codeception test showing how that is failing and work to fix the test.

some background how bidirectional stuff is stored (partly due to backward compatibility)

quasel commented 3 years ago

Place to take a look as mentioned by @sc0ttkclark for a different issues in slack https://github.com/pods-framework/pods/blob/main/classes/PodsAPI.php#L4210 deleting relationship data: https://github.com/pods-framework/pods/blob/main/classes/PodsAPI.php#L5862 saving relationship data: https://github.com/pods-framework/pods/blob/main/classes/PodsAPI.php#L4438

sc0ttkclark commented 3 years ago

We should retest this to see if it's still happening in 2.8, I fixed some code here before 2.8 release which mailed dealt with user objects on a multi site but could have had something to do with the issue reported here too.

TrevorSqE commented 2 years ago

Just tested this one with 2.8.4.1, and it's still an issue. I have two CPTs "person" and "service" with a bi-directional relationship field on each, multi-select. If I'm editing Service A, I can add Person X and Person Y, but not then delete Person Y; I have to go and edit Person Y (where Service A is not selected) and then save, at which point they are removed from the field on Service A.

JoryHogeveen commented 2 years ago

Hi @TrevorSqE I cannot seem to reproduce this behavior on my local installation running 2.8.4.1. What multiselect UI did you choose? List view?