Computed fields of computed fields

Created on 27 September 2021, about 3 years ago
Updated 30 September 2021, about 3 years ago

I'm using a nested level of computed fields. I have paragraphs with computed fields, then another computed field that's a sibling to the paragraph field. The idea is that the parent computed field should check the values of the computed fields in the paragraphs, then show a "total" of each paragraph's computed field.

However, this doesn't appear to work well. The total appears to be using the computed field value from the previous paragraph save, not building the new revision first.

I thought - Oh well, I'll just compute directly against each paragraph, but the issue appears to be more fundamental - the values within the paragraphs themselves are not updating properly at the time of computation - even if the grand total was computed from values in each paragraph, the value would still be incorrect.

I can resolve this by saving the parent node twice, but that's not ideal and difficult (though not impossible) to do as an update hook.

It's not clear this is actually a computed_field problem (possibly having to do with the save order of referenced entity revisions), but has anyone hit this issue before, and is there a strategy for solving it?

💬 Support request
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada TrevorBradley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany derheap

    I have the same problem.
    I have a node with several paragraphs. I do a calculation on the paragraphs, this works.
    But in `hook_node_presave` or `hook_entity_presave` the calculated fields are still zero.
    I might ditch the computed fields and use real fields (does that solve the problem) or do the calcualtion twice …

Production build 0.71.5 2024