Issue 2174 proposed fix#2759
Conversation
|
This seems a bit complex of a change honestly. I would have expected that to do this we would essentially need to move some logic from after the before_action hooks to before. Additionally, attempting to deduplicate loads using something like this: Will almost certainly bite us at some point, vs just checking if a given thing is loaded or splitting the loads somewhere earlier etc. |
|
After going over my notes and combing through the code again, I tried to make it without changing too much of the normal functionality. Please read below for my evaluations on what could be done. High risk is something I believe should be avoided outright. Low risk I believe should certainly be considered, but maybe too risky to implement in this PR and saved for a different one. High risk: High risk: Fix: Low risk: Low risk: Low risk: My suggestion would be for me to go back and use a diff instead of a dedupe, and then the low-risk issues could be attempted as a separate PR issue. |
|
Hello! I think that this implementation causes too many issues and that there isn't really a good way to do this. Instead what I think we should do is add a simple validation that |
Contributor checklist
Leave anything that you believe does not apply unchecked.
Addressing issue 2174: before_action hooks cannot add loads or calculations during read actions
The source of the issues was two separate bugs within the pipeline timing.
Bug 1 was having post-read using a stale query. It saw the outer query and primarily used the outer query. The new_query would be made, but the read action would never actually load the new query and would be silently dropped.
Bug 2 related to splitting calculations too early. When calculations are split, they are separated into 3 their 3 buckets. However, this was done before the before_action. This caused an issue where if the hook adds a new calculation, it would land on on query.calculations but never get merged with the existing calculation lists.
To fix this, "hook just ran" and "execute query/post-read" paths to reprocess calculations added by the hook, refresh calculation context, re-run forbidden-field deselection, and finally append the new data-layer calculation. split_and_load_calculations are used earlier in the pipeline to ensure the data is not dropped. Take only new_entries in calculations_in_query, hydrate them, and then append to data_layer_calculations with proper authorization on expressions to allow hook-added calculations without re-processing calculations handled pre-hook.
Next was adding the post-read hook-added loads without replacing the entire query. Required some helper functions to not break normal reads. Some post-read pipeline was cleaned up; loads, calculations, and field authorization were split from pagination, to better compare hook changes and what was ran against the DB.
Tests were added to prove running and to test against regression.