fix: 404 an unknown product_id in curated deals, don't fabricate a price - #58
Open
garvitkaushik-123 wants to merge 1 commit into
Open
Conversation
create_curated_deal's comment says "A known-but-unpriced product... is a 422 -- never a fabricated price," and the code delivers on that for a product that exists but has no base/floor CPM (via catalog_service.priceable_cpm). It didn't deliver on it for a product_id that doesn't exist in the catalog at all: that case skipped price resolution entirely and fell through to the hardcoded $12 CPM default meant only for the no-product-id-supplied case, then minted and persisted a "confirmed" deal at that fabricated price. No error, anywhere. POST /api/v1/deals/curated has no auth dependency, so this was reachable by anyone with a typo, a stale product reference, or a deliberately made-up product_id -- and unlike a mispriced quote, this endpoint creates a live confirmed deal record directly. Fix: when product_id is supplied but not found in the catalog, 404 product_not_found -- same error shape quote_service.create_quote already uses for the identical situation. The $12 CPM default now only applies when no product_id is given at all, which the code was always treating as a separate, legitimate case. create_curated_deal had zero test coverage before this. Added tests/unit/test_curated_deal.py: the 404 case (the bug), a known product pricing off its real base_cpm + curator fee, the 422 known-but-unpriced case (unchanged by this fix), the no-product-id generic-default case (also unchanged), and curator_not_found for completeness. Full suite: 1408 passed. ruff check / format clean. Closes IABTechLab#57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #57.
create_curated_deal's comment says "A known-but-unpriced product... is a 422 — never a fabricated price," and the code delivers on that for a product that exists but has nobase_cpm/floor_cpm(viacatalog_service.priceable_cpm). It didn't deliver on it for aproduct_idthat doesn't exist in the catalog at all: that case skipped price resolution entirely and fell through to the hardcoded$12CPM default meant only for the no-product_id-supplied case, then minted and persisted aconfirmeddeal at that fabricated price. No error, anywhere.POST /api/v1/deals/curatedhas no auth dependency at all, so this was reachable by anyone — a typo, a stale product reference, a deliberately made-upproduct_id— and unlike a mispriced quote, this endpoint creates a live confirmed deal record directly, not something pending booking. See #57 for the full repro (typo'd product_id against a $45/$35 real product → confirmed deal at $13.20 total CPM).Fix
When
product_idis supplied but not found in the catalog,404 product_not_found— the same error shapequote_service.create_quotealready uses for the identical situation. The$12CPM default now only applies when noproduct_idis given at all, which the code was always treating as a separate, legitimate case (a generic curated deal with no specific product reference).Test plan
create_curated_dealhad zero test coverage before this. Addedtests/unit/test_curated_deal.py:product_id→ 404, no deal minted (the bug)base_cpm+ curator feeproduct_idat all → generic $12 default (unchanged, confirms this legitimate case wasn't broken)curator_not_found→ 404, for completenessFull suite: 1408 passed, no regressions.
ruff check/format --checkclean.Closes #57