Skip to content

Enforce one product per purchasable object - #3847

Open
cp-at-mit wants to merge 2 commits into
mainfrom
11729-should-not-allow-multiple-products-for-same-object-id-and-type
Open

Enforce one product per purchasable object#3847
cp-at-mit wants to merge 2 commits into
mainfrom
11729-should-not-allow-multiple-products-for-same-object-id-and-type

Conversation

@cp-at-mit

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

https://github.com/mitodl/hq/issues/11729

Description (What does it do?)

Updates Product uniqueness to always enforce a single product per (object_id, content_type) pair, instead of allowing duplicates when one is inactive. Adds a migration to replace the old conditional constraint and updates the model test to cover both active and inactive duplicate creation attempts.

How can this be tested?

Create a product, then attempt to create a second active product for the same object. This should not work even if the first product is deactivated.

Updates `Product` uniqueness to always enforce a single product per `(object_id, content_type)` pair, instead of allowing duplicates when one is inactive. Adds a migration to replace the old conditional constraint and updates the model test to cover both active and inactive duplicate creation attempts.
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

OpenAPI Changes

Show/hide changes
## Changes for v0.yaml:
12 changes: 0 error, 0 warning, 12 info
info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `results/items/redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `results/items/redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `201`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `201`

info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v0.yaml
	in API GET /api/v0/orders/receipt/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v0.yaml
	in API GET /api/v0/orders/receipt/{id}/
		the `purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`



## Changes for v1.yaml:
12 changes: 0 error, 0 warning, 12 info
info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `results/items/redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `results/items/redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `201`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `201`

info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v1.yaml
	in API GET /api/v0/orders/receipt/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v1.yaml
	in API GET /api/v0/orders/receipt/{id}/
		the `purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`



## Changes for v2.yaml:
12 changes: 0 error, 0 warning, 12 info
info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `results/items/redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `results/items/redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `201`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API POST /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `201`

info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API GET /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API PATCH /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `redeemed_order/purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API PUT /api/v0/discounts/{parent_lookup_redeemed_discount}/redemptions/{id}/
		the `redeemed_order/purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`

info	[response-property-all-of-removed] at head/openapi/specs/v2.yaml
	in API GET /api/v0/orders/receipt/{id}/
		removed `#/components/schemas/ExtendedLegalAddress` from the `purchaser` response property `allOf` list for the response status `200`

info	[response-property-type-specialized] at head/openapi/specs/v2.yaml
	in API GET /api/v0/orders/receipt/{id}/
		the `purchaser` response's property `type` was narrowed from `any` to `array<object>` for status `200`



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

@cp-at-mit
cp-at-mit marked this pull request as ready for review August 12, 2026 16:24
@annagav
annagav self-requested a review August 13, 2026 12:49
@annagav annagav self-assigned this Aug 13, 2026

@annagav annagav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we run a migration to resolve any duplicates first before setting the constraint?

@cp-at-mit
cp-at-mit requested a review from annagav August 14, 2026 17:46

@annagav annagav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants