fix(db) make dao:cache_key to fallback to primary_key if nothing from cache_key was found #8553
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This makes the
cache_key
function more robust. For example this code may be quite common:Now if
service
schema hascache_key = { "name" }
(it does not, but just as an example) you can see that thelocal cache_key
will then be same for all theservices
(no matter if they are pointing to different service by id), as theroute.service
is not expanded by default, and it only contains the primary key, in this caseid
.The change in this commit is that it will now actually fallback to
primary_key = { "id" }
in case it cannot find anything by thecache_key
. As it can be seen in code above, it is quite easy to make this mistake, and not see the mistake. User could fix their code by calling:instead of:
But as this can potentially be dangerous if forgotten, I think it is worth to fallback to
primary_key
by default on such case.