-
Notifications
You must be signed in to change notification settings - Fork 2
Make min max product price required #3262
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
base: main
Are you sure you want to change the base?
Conversation
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
90dc4b8 to
54c8e01
Compare
for more information, see https://pre-commit.ci
|
|
||
| ProgramPage = apps.get_model("cms", "ProgramPage") | ||
| for program in ProgramPage.objects.filter(min_price=None): | ||
| program.min_price = program.price if program.price is not None else 0 | ||
| program.save(update_fields=["min_price"]) | ||
|
|
||
| for program in ProgramPage.objects.filter(max_price=None): | ||
| program.max_price = program.price if program.price is not None else 0 | ||
| program.save(update_fields=["max_price"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The data migration incorrectly assigns the price StreamField object directly to the min_price SmallIntegerField, which will cause data loss or a crash during migration.
Severity: CRITICAL
Suggested Fix
Update the migration logic to correctly parse the numeric value from within the price StreamField. It should iterate through the stream blocks, access the price_details block, and extract the numeric value from its text field (e.g., price[0].value['text']), converting it to an integer. The check for an empty stream should also be corrected (e.g., if course.price:).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: cms/migrations/0055_populate_min_max_price.py#L15-L23
Potential issue: The data migration attempts to populate the new `min_price` and
`max_price` fields from the existing `price` `StreamField`. However, the logic
`course.min_price = course.price if course.price is not None else 0` is incorrect. It
assigns the entire `StreamField` object, not a numeric value from within it, to the
`SmallIntegerField`. Additionally, the condition `course.price is not None` is almost
always true for a `StreamField`, which returns an empty list-like object when empty, not
`None`. This will cause the migration to either fail due to a type mismatch or silently
convert all values to 0, effectively losing existing price data.
Did we get this right? 👍 / 👎 to inform future reviews.
What are the relevant tickets?
Fix https://github.com/mitodl/hq/issues/9910
Description (What does it do?)
makes min max price required on the product page
validates min_price and max_price are set when saving the course page in the CMS
How can this be tested?
Run the migrations
Take a look at your existing product pages.
Make sure min max price were populated from the existing price field.
Go to program or course page make sure that the fields are required now.