U4-10289 - IdkMap cache can cause the entity service to return invalid results

Created by Claus Jensen 14 Aug 2017, 09:15:20 Updated by Stephan 18 Aug 2017, 19:45:55

Tags: Unscheduled

Subtask of: U4-9609

EntityService has methods for getting entity by Id & objectType which does a lookup in the database and caches the Id <-> UniqueId inside a IdkMap.

The problem here is that we only cache a dictionary of either int or Guid, to the opposite.

Assuming you make a valid lookup for Id: 1115 of type Document, the database is queried for this entry and it is now cached in the IdkMap.

Afterwards a lookup is made for Id: 1115 of type Media. Since we have already cached an entity with Id 1115 (with no indication of what entity type it is), we just return the result for that Id, completely ignoring whether the requested object type actually should give a match on that Id.


Claus Jensen 14 Aug 2017, 09:41:36

PR: https://github.com/umbraco/Umbraco-CMS/pull/2128

I have added some internal composite key classes for the IdkMap class to use for caching.

Have added a note on the PR for @Shandem

Claus Jensen 15 Aug 2017, 08:22:11

Fixed up a bit and added notes to the PR

Stephan 15 Aug 2017, 15:57:05

Note: discussing the implementation w/@claus on Slack - there's probably a simpler solution.

Claus Jensen 15 Aug 2017, 23:33:05

Fixing up tomorrow

Stephan 17 Aug 2017, 20:02:56

Have added one comment on the PR - but really it's only to be annoying ;-) Totally happy to merge the code now, but won't be able to do it before a few days. So if you want to merge, I approve!

Stephan 18 Aug 2017, 19:45:50

happy, merged

Priority: Normal

Type: Bug

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 7.6.5

Due in version: 7.6.6

Sprint: Sprint 65

Story Points: 3