Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidental mutation side effect breaking the Objects API v1 registration #5043

Merged
merged 5 commits into from
Jan 28, 2025

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented Jan 27, 2025

Closes #5035

Changes

  • Fixed wrong FormVariable records being created for components inside repeating groups
  • Fixed unintended mutation adding the components of step 2-end to the configuration of step 1, leading to extra keys being submitted in the Objects API registration (legacy)
  • Small quality of life thing: display the variable count on each tab in the variables editor
  • Small refactor: removed some code duplication

The regression test + bugfix can be cherrypicked to the stable/3.0.x branch for backport purposes, the rest is for the main branch.

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.71%. Comparing base (306022a) to head (9e90a4c).
Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5043   +/-   ##
=======================================
  Coverage   96.71%   96.71%           
=======================================
  Files         770      770           
  Lines       26488    26489    +1     
  Branches     3453     3453           
=======================================
+ Hits        25617    25618    +1     
  Misses        607      607           
  Partials      264      264           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sergei-maertens sergei-maertens changed the title WIP bugfixes Fix accidental mutation side effect breaking the Objects API v1 registration Jan 27, 2025
@sergei-maertens sergei-maertens marked this pull request as ready for review January 27, 2025 15:11
@@ -36,12 +37,16 @@ const VariablesEditor = ({variables, onAdd, onDelete, onChange, onFieldChange})
<Tabs>
<TabList>
<Tab hasErrors={componentVariables.some(variable => variableHasErrors(variable))}>
{intl.formatMessage(VARIABLE_SOURCES_GROUP_LABELS.component)}
{intl.formatMessage(VARIABLE_SOURCES_GROUP_LABELS.component)} (
{componentVariables.length})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

…cords

Components nested in repeating groups are not real variables. The
frontend code showed these in the variables table AND this also
caused them to be PUT to the backend, resulting in crashes when
processing file uploads because there are no saved submission variables
available for them.

Unfortunately, this doesn't appear to fix the problem with too much
keys being included in the submission data during registration, so
it must have a different root cause.
This is available on the model too, so we can build on
top of that.
…ep configuration

The total configuration wrapper merges the configuration wrapper of
each step into a single object for optimized access to values/
components. It takes the first step and merges the remaining steps into
it. However, this had the unintended side-effect of mutating the config
of the first step, manifesting in the objects API v1 registration with
the json_summary tag which contained extra, unexpected keys in the
submission data of the first step.

Fixed by making a deep copy first to end up with a different instance
that can be safely mutated.
@sergei-maertens sergei-maertens force-pushed the issue/5035-duplicated-json-summary-nodes branch from 2bbfe66 to 9e90a4c Compare January 28, 2025 16:46
@sergei-maertens sergei-maertens merged commit 65097fa into master Jan 28, 2025
29 of 33 checks passed
@sergei-maertens sergei-maertens deleted the issue/5035-duplicated-json-summary-nodes branch January 28, 2025 17:46
sergei-maertens added a commit that referenced this pull request Jan 28, 2025
Fix 1:

Components nested in repeating groups are not real variables. The
frontend code showed these in the variables table AND this also
caused them to be PUT to the backend, resulting in crashes when
processing file uploads because there are no saved submission variables
available for them.

Unfortunately, this doesn't appear to fix the problem with too much
keys being included in the submission data during registration, so
it must have a different root cause.

Fix 2:

Avoid the total configuration wrapper mutating the first step configuration

The total configuration wrapper merges the configuration wrapper of
each step into a single object for optimized access to values/
components. It takes the first step and merges the remaining steps into
it. However, this had the unintended side-effect of mutating the config
of the first step, manifesting in the objects API v1 registration with
the json_summary tag which contained extra, unexpected keys in the
submission data of the first step.

Fixed by making a deep copy first to end up with a different instance
that can be safely mutated.

Backport-of: #5043
@sergei-maertens sergei-maertens added the needs-backport Fix must be backported to stable release branch label Jan 28, 2025
sergei-maertens added a commit that referenced this pull request Jan 28, 2025
Fix 1:

Components nested in repeating groups are not real variables. The
frontend code showed these in the variables table AND this also
caused them to be PUT to the backend, resulting in crashes when
processing file uploads because there are no saved submission variables
available for them.

Unfortunately, this doesn't appear to fix the problem with too much
keys being included in the submission data during registration, so
it must have a different root cause.

Fix 2:

Avoid the total configuration wrapper mutating the first step configuration

The total configuration wrapper merges the configuration wrapper of
each step into a single object for optimized access to values/
components. It takes the first step and merges the remaining steps into
it. However, this had the unintended side-effect of mutating the config
of the first step, manifesting in the objects API v1 registration with
the json_summary tag which contained extra, unexpected keys in the
submission data of the first step.

Fixed by making a deep copy first to end up with a different instance
that can be safely mutated.

Backport-of: #5043
@sergei-maertens
Copy link
Member Author

Backports:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-backport Fix must be backported to stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(legacy) Object API registration: json_summary contains "duplicate" nodes
2 participants