cms
cms copied to clipboard
Bug happened when saving an Entries field, the selected entries are there twice.
Description
A weird bug happened when saving an Entries field.
Steps to reproduce
On my Catalog section, under a Entries field, I select 2 entries (from a Product (structure section)). Save. And when the page reload, each Products are there 2 times. I was thinking about a UI issue, but if a query this specific entry I can see 4 ids (2 x 2).
To see it in action: https://recordit.co/FYxYyMGIUW
Notes:
- I try with one, two and more Products, same issue. If I delete the dups and save back, they came back again.
- I try with a fresh new Catalog, the same issue happened. But if I try with a fresh Products, the issue dont happen.
I then try to resave all the entries (craft cli), a ./craft utils/repair/section-structure product
, the issue is still there.
Any way to get that fix? I got 400+ products create by the client, so start over isnt a solution.
Additional info
- Craft version: 3.5.15
- PHP version: 7.3.24
- Database driver & version: MySQL 10.1.46
Maybe related? #6150
@Mosnar The products aren't displayed twice in the panel view (panel/entries/product), they are in the field (Selected Products) under a Catalog (aka the relation are saved twice).
It may be related, but not the same behaviour.
@jesuismaxime That's the same behavior I saw actually - the relation fields showed the same entries twice.
@Mosnar ok, did you managed to find a solution on your side since May ?
p.s. we do use the project config yaml and this was initiated on a local env and I don't have this issue there. Only on my staging env
@jesuismaxime The issue for me was that there was a dangling structure
in the database that simply needed to be deleted. Once I deleted the extra, everything went back to normal. I would test locally and allow someone from P&T to chime in before calling that a solution.
@Mosnar are you on the Discord server?
@Mosnar or at least could you describe which part(s) you had to delete? I dont' have a duplicated Structure in craft_sections
so I guess it is more about the entries and/or their relations ?
We have seen this happen once before. It was due to duplicate data getting stored in the relations
table somehow. We weren’t able to identify how that happened in the first place though.
If you delete your existing relations and re-save, then re-add the relations, do the relations still get duplicated? If so please send your Composer files and a database backup over to [email protected] and we can look into it from there.
I had to roll back to a channel structure (that "fix" the issue) and told the client to order the entries using the date (which anyway in my case is better; but it was a demand of the client even if we did'nt suggest that.
As for your question; Yes I had delete all the relations (empty the field), save, add some relations, save : duplicate.
The only way to have a relation "not duplicated" was to create a new product
Entry. That one, once linked, did'nt display twice (but if I add one or more product
relations, those that was created before the channel/structure change were displayed twice.
I can re-test locally, if the issue still happen I would be glad to send you the files, but at first that issue did not happen on my local env; my guess is that the 'resaving entries' jobs did not go well after a staging deployment.
Update: still did not happen on a local env. My guess is really on the first "resave entries" jobs or what ever Craft is doing under the hood when a change of that type is done 'manually' that seems to not go well when it comes from a config/project
I had the same problem, and also dangling entries in the structureelements
table and an entry without the dateDeleted
set correctly in the structures
table. Somehow it seams the structure was not deleted correctly. It seams to be correct in the project config.
I fixed this by applying the following SQL Commands, where ID 2 is the dangling structure:
DELETE FROM structureelements WHERE structureId = 2 AND level != 0;
UPDATE structureelements SET rgt = 2, dateUpdated = now() WHERE structureId = 2 AND level = 0;
UPDATE structures SET dateDeleted = now() WHERE id = 2;
Additional Info
- Craft CMS Version: 3.7.28
- PHP Version 7.3.29
@forcehobbit How did you find "dangling entries" in the structureelements
table?
@johndwells You should be able to check and see what structure is referenced by your section or category group in the "sections" or "categorygroups" tables respectively. The problematic structure is going to be the one that isn't referenced in those areas and is also not soft-deleted.
Thanks @Mosnar. As far as I can tell then, I don't have any "dangling" entries.
And yet I do have an instance where a relationship field for a particular draft entry has duplicated relationships presented in the CP (and also the front-end).
So I've looked it up and sure enough, I have duplicate rows in the relations
table, but for the draft. Each relationship in the field is duplicated twice in table.
The CP/front-end shows the duplicated relationships 4 times.
And if I manually delete one of these duplicated rows, then the 4x duplication in the CP/front-end goes away, and I'm left only with 1.
(I have sent a DB dump, project config & composer files to P&T).