Skip to content

Conversation

@annagav
Copy link
Contributor

@annagav annagav commented Feb 3, 2026

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.

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

OpenAPI Changes

Show/hide ## Changes for v0.yaml:
## Changes for v0.yaml:
6 changes: 2 error, 0 warning, 4 info
error	[api-path-removed-without-deprecation] at base/openapi/specs/v0.yaml	
	in API GET /api/v3/program_enrollments/
		api path removed without deprecation

error	[api-path-removed-without-deprecation] at base/openapi/specs/v0.yaml	
	in API GET /api/v3/program_enrollments/{program_id}/
		api path removed without deprecation

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3ProgramCertificate'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3SimpleProgram'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3UserProgramEnrollment'

info	[response-property-enum-value-removed] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/b2b/enroll/{readable_id}/
		removed the 'b2b-error-not-enrollable' enum value from the 'result/allOf[#/components/schemas/ResultEnum]/' response property for the response status '200'



## Changes for v1.yaml:
6 changes: 2 error, 0 warning, 4 info
error	[api-path-removed-without-deprecation] at base/openapi/specs/v1.yaml	
	in API GET /api/v3/program_enrollments/
		api path removed without deprecation

error	[api-path-removed-without-deprecation] at base/openapi/specs/v1.yaml	
	in API GET /api/v3/program_enrollments/{program_id}/
		api path removed without deprecation

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3ProgramCertificate'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3SimpleProgram'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3UserProgramEnrollment'

info	[response-property-enum-value-removed] at head/openapi/specs/v1.yaml	
	in API POST /api/v0/b2b/enroll/{readable_id}/
		removed the 'b2b-error-not-enrollable' enum value from the 'result/allOf[#/components/schemas/ResultEnum]/' response property for the response status '200'



## Changes for v2.yaml:
6 changes: 2 error, 0 warning, 4 info
error	[api-path-removed-without-deprecation] at base/openapi/specs/v2.yaml	
	in API GET /api/v3/program_enrollments/
		api path removed without deprecation

error	[api-path-removed-without-deprecation] at base/openapi/specs/v2.yaml	
	in API GET /api/v3/program_enrollments/{program_id}/
		api path removed without deprecation

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3ProgramCertificate'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3SimpleProgram'

info	[api-schema-removed] 	
	in components/schemas
		removed the schema 'V3UserProgramEnrollment'

info	[response-property-enum-value-removed] at head/openapi/specs/v2.yaml	
	in API POST /api/v0/b2b/enroll/{readable_id}/
		removed the 'b2b-error-not-enrollable' enum value from the 'result/allOf[#/components/schemas/ResultEnum]/' response property for the response status '200'



Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@annagav annagav marked this pull request as ready for review February 5, 2026 02:19
@annagav annagav force-pushed the ag/import_course_with_min_max_price branch from 90dc4b8 to 54c8e01 Compare February 6, 2026 13:30
Comment on lines +15 to +23

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"])
Copy link

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.

@annagav annagav marked this pull request as draft February 6, 2026 14:42
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.

1 participant