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

Remove SubmissionValueVariable.form_variable FK field to avoid confusion #5071

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

sergei-maertens
Copy link
Member

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

Closes #5058

Changes

  • Updated factory to ensure that a form variable exists for submission value variable (via factory)
  • Updated tests to specify sufficient metadata for the form variables. I actually did a POC first where each variable was created explicitly before updating the factory to make sure there's no false confidence through unintended factory side effects.
  • Removed the form_variable FK field as it's not needed and may otherwise cause confusion.

There's still an interesting cascade delete now in the code where a form definition can delete the related form variable, leading to a submission variable existing without the matching form variable being present. I think our code is robust enough to deal with this, but it's something that could cause issues in the future if the service layer is not used to process submission values.

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

@sergei-maertens sergei-maertens force-pushed the issue/5058-remove-unused-form-variable branch from 00ef125 to 09b3079 Compare February 3, 2025 11:27
This sets up the factory to make sure the underlying FormVariable also
exists for a given SubmissionValueVariable instance, but we *do* need
to handle the case where this integrity is broken during runtime as
records may be gone for whatever reason (and there are tests for this
situation).

Instead of crashing hard, we just log a message and fall back to just
the raw underlying JSON value. The casting to python types is
troublesome even when all information is available and the scope is
too big to solve that here.
@sergei-maertens sergei-maertens force-pushed the issue/5058-remove-unused-form-variable branch from 09b3079 to c626d78 Compare February 3, 2025 13:23
@sergei-maertens sergei-maertens changed the title ⚗️ Check if we can remove the form_variable FK on submission value variable Remove SubmissionValueVariable.form_variable FK field to avoid confusion Feb 3, 2025
@sergei-maertens sergei-maertens marked this pull request as ready for review February 3, 2025 13:27
Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.72%. Comparing base (3f79ba2) to head (c626d78).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5071   +/-   ##
=======================================
  Coverage   96.72%   96.72%           
=======================================
  Files         770      770           
  Lines       26517    26523    +6     
  Branches     3454     3454           
=======================================
+ Hits        25649    25655    +6     
  Misses        606      606           
  Partials      262      262           

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

@@ -359,10 +351,12 @@ class SubmissionValueVariable(models.Model):

objects = SubmissionValueVariableManager()

form_variable: FormVariable | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed, can't we remove the property as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

we're still setting this attribute dynamically and lots of code requires self.form_variable to be defined in some capacity. This type annotation declares that it is a known attribute with a particular expected type. Not defining this here would definitely fail the type checking in CI :)

@sergei-maertens sergei-maertens merged commit 5afe627 into master Feb 5, 2025
35 checks passed
@sergei-maertens sergei-maertens deleted the issue/5058-remove-unused-form-variable branch February 5, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants