U4-6784 - 7.2.2 Multiple Media Picker - Failed to retrieve entity data for ids

Created by fneves 02 Jul 2015, 13:58:05 Updated by Tom Fulton 23 Sep 2015, 00:11:11

We have a Multiple Media Picker to manage image galleries. Some of our media pickers have around one hundred images selected. The media items were selected, the content was saved and published. Everything looks ok on the website, but when we open the content on the backoffice, there's an exception stating:

Received an error from the server Failed to retrieve entity data for ids 2621,2618,2624,2629,2630,2632,2633,2635,2639,2641,2648,2651,2652,2657,2659,2661,2662,2663,2666,2667,2668,2669,2671,2675,2670,2674,2673,2677,2678,2681,2682,2684,2554,2555,2556,2558,2560,2564,2565,2566,2568,2569,2571,2572,2574,2575,2582,2581,2583,2725,2726,2727,2723,2730,2729,2728,2742,2745,2743,2746,2747,2750,2749,2752,2756,2757,2758,2761

An item with the same key has already been added.

We already tried to republish the galleries, but it didn't help.

3 Attachments


Jeavon Leopold 21 Sep 2015, 13:29:45

Pull request to fix this issue here https://github.com/umbraco/Umbraco-CMS/pull/795

Jeavon Leopold 21 Sep 2015, 13:30:45

I have traced this issue into the sql query which is not correctly grouping the properties and therefore causing the entity service to create multiple entites, attached is a sql query before and after of my fix

CurrentQuery.png - On row 16 you can see a stray property that should be on row 6, this is causing the entity service to return two 1240 NewQuery.png - added id to the sort order, you can see all properties are correctly grouped together

Jeavon Leopold 21 Sep 2015, 13:49:10

@Shandem can you please review my change, I didn't break any tests but I'm not 100% sure of any unintended affect of the change elsewhere?

Shannon Deminick 21 Sep 2015, 18:36:06

Have assigned to Stephen, he or I will have a look tomorrow

Jeavon Leopold 21 Sep 2015, 19:15:49


Tom Fulton 21 Sep 2015, 19:43:36

@crumpled_jeavon Thanks for your work on this! This actually fixes a similar issue I've been trying to track down, where duplicate nodes will show in the media tree (same ID but multiple entries in the tree). In my case though, I don't notice any improper grouping when running the SQL statement, but I definitely see duplicate entities created during the mapping. I worked around this temporarily by filtering the returned entities to a distinct Id ([https://github.com/tomfulton/Umbraco-CMS/commit/47bcfd572d45c26d30bc19ba40a92921ef61a9d5 code]), but your patch seems to fix this for me.

Jeavon Leopold 21 Sep 2015, 20:04:03

Wow @tomnf that's very interesting, from my investigation the issue with using distinct is that you will be missing properties on the entities from the ignored entities

Stephan 22 Sep 2015, 13:30:23


The way things work, entities are built by the internal UmbracoEntityRelator class, which checks the uniqueID to figure out whether it is adding data to the "current" entity it is building, or whether it needs to create a new entity. With the current request, we can get (entity E1, prop P1), (entity E2, prop P1), (entity E1, prop P2) if E1 and E2 have the same sort order. This would cause the relator to create entity E1 twice, with two sets of properties.

Sorting by "sortOrder, id" ensures that the records for one entity will be grouped = the entity is created once and only once. Merging the PR;

As far as I can tell, content is not using the same methodology to fetch entities (there is a note about it in the code) so is not impacted.

Stephan 22 Sep 2015, 13:43:14

Commit ef6fd54af341a5f4e33aea397a36cd0e60c2c13b

Jeavon Leopold 22 Sep 2015, 13:45:43

Fantastic, thanks @zpqrtbnk

Tom Fulton 23 Sep 2015, 00:11:11

Thanks for the additional info @crumpled_jeavon @zpqrtbnk . With that I took a deeper look on my case (even though it's fixed I just had to know why :)).

As mentioned in my case, when running the big query in SSMS, everything looks grouped properly to me. But, PetaPoco was interpreting the order differently than shown in SSMS, and through debugging I could see the 'stray' property not grouped with it's node, even though it was in SSMS. Fun! :)

Also, I noticed that all of my duplicate child nodes seem to had a sortOrder of 0 in the DB which might have been related.

Also, maybe worth noting that the duplicate nodes eventually go away on our install after deleting some other child nodes. Not sure what the difference was, maybe the sortOrder getting updated.

Anyway, all fixed now, thanks both for your work!

Priority: Major

Type: Bug

State: Fixed

Assignee: Stephan

Difficulty: Normal


Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.2.6, 7.2.7, 7.2.8

Due in version: 7.3.0


Story Points: