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

Replace form price logic with variable + normal logic #4856

Merged
merged 10 commits into from
Nov 28, 2024

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented Nov 25, 2024

Closes #4771

Changes

  • Removed UI and API endpoints to manage price logic
  • Added automatic migration to convert to regular logic rules
  • Updated tests
  • Updated documentation

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form (price logic was never copied along)
    • Checked import/export of a form (price logic was never imported along)
    • 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
  • 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 cleanup/4771-remove-price-logic branch from a4eb8db to 702b8e3 Compare November 26, 2024 07:42
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.61%. Comparing base (de45256) to head (bf46b3e).
Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4856   +/-   ##
=======================================
  Coverage   96.61%   96.61%           
=======================================
  Files         752      751    -1     
  Lines       25725    25699   -26     
  Branches     3406     3401    -5     
=======================================
- Hits        24853    24828   -25     
+ Misses        610      609    -1     
  Partials      262      262           

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

@sergei-maertens sergei-maertens force-pushed the cleanup/4771-remove-price-logic branch from 702b8e3 to 6cb7e41 Compare November 26, 2024 10:08
@sergei-maertens sergei-maertens marked this pull request as ready for review November 26, 2024 10:42
@sergei-maertens sergei-maertens force-pushed the cleanup/4771-remove-price-logic branch from 323e833 to f5acb7a Compare November 26, 2024 13:17
@sergei-maertens sergei-maertens changed the title Cleanup/4771 remove price logic Replace form price logic with variable + normal logic Nov 26, 2024
@vaszig vaszig requested review from vaszig and removed request for stevenbal November 27, 2024 14:41
@sergei-maertens sergei-maertens force-pushed the cleanup/4771-remove-price-logic branch from f5acb7a to 36e255a Compare November 27, 2024 15:55
@sergei-maertens sergei-maertens marked this pull request as draft November 28, 2024 10:36
…logic

Converted the current behaviour of price logic rules into assignments of
the price logic variable value, including the fallback behaviour to the
product price if no logic rule matches. This last bit is slightly
nuanced, since changing the price on the product no longer results in
the fallback case being automatically updated along, and that requires a
note in the changelog (!).

At first, I wanted to trigger the logic rules only when the last step
was reached, using trigger_from_step, but I'm unsure that it behaves
correctly if the last step is somehow made not applicable with other
logic rules, so instead these rules are always evaluated. If it's safe,
users can update the auto-migrated rules to optimize performance.

I've also opted to not implement the reverse operation due to the
involved complexity - we should definitely recommend to make database
backups before upgrading to 3.0. We can be a bit bolder than usualy
because it's part of a major version with other breaking changes anyway,
and it should be fine (tm) for the majority of the cases.
Price logic rules are replaced with normal logic rules that assign the
calculated price to a variable, and instead you should point to the
form variable holding the calculated value.
We can't effectively remove this codepath yet because it's still used
in the migration tests to ensure the calculated price before and after
migrating has the same outcome, rather than testing the implementation
details/state of the database.

API endpoints and UI are removed, so there should not be a way to be
able to get new price logic rules in the system. We'll also remove
admin access and support for copying them when copying a form.
There are some slight behaviour changes here that need to be documented,
namely the refusal to fall back to product price if price is derived
from a variable, and the fact we can no longer make some sanity check
assertions in the test method. However, the behaviour is covered by
the main assertion of the test.
... and other things that should've had their documentation
added already but I neglected to do so.
@sergei-maertens sergei-maertens force-pushed the cleanup/4771-remove-price-logic branch from 36e255a to bf46b3e Compare November 28, 2024 11:31
@sergei-maertens sergei-maertens marked this pull request as ready for review November 28, 2024 11:42
Copy link
Contributor

@vaszig vaszig left a comment

Choose a reason for hiding this comment

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

Should we add the remark to the changelog about making database backups before upgrading to 3.0 (mentioned in one of your commit messages)?

@@ -76,6 +77,12 @@ def get_submission_price(submission: Submission) -> Decimal:
data = submission.data
# test the rules one by one, if relevant
price_rules = form.formpricelogic_set.all()
if price_rules:
warnings.warn(
"Price logic rules are no longer supported. The left-over implementation "
Copy link
Contributor

Choose a reason for hiding this comment

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

We mean the model as well, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's implied! I can't delete the models yet because then this implementation breaks and that breaks the tests. I'll make sure to get rid of that once 3.0 is released.

@sergei-maertens
Copy link
Member Author

Should we add the remark to the changelog about making database backups before upgrading to 3.0 (mentioned in one of your commit messages)?

Yeah I think a general remarks like that is needed either way. Something like "As always we recommend making and testing a database backup before upgrading, especially on major versions with breaking changes." Just something to keep in mind for next month!

@sergei-maertens sergei-maertens merged commit f0aa235 into master Nov 28, 2024
37 checks passed
@sergei-maertens sergei-maertens deleted the cleanup/4771-remove-price-logic branch November 28, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate (and remove) price logic
2 participants