Skip to content

Find parent issues by variant UPC and SKU - #670

Merged
bpepple merged 3 commits into
Metron-Project:masterfrom
erickolb:fix/variant-upc-sku-search
Nov 3, 2026
Merged

bpepple merged 3 commits into
Metron-Project:masterfrom
erickolb:fix/variant-upc-sku-search

Conversation

@erickolb

@erickolb erickolb commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #669.

Issue searches check only the main cover's UPC or distributor SKU, even when a matching value is stored on a variant. This change checks both the issue and its variants for exact UPC/SKU searches in the API and website, and for the API's upc_starts_with filter.

A shared IssueCoverIdentifier filter returns each matching parent issue once and preserves other supplied filters. The response format stays the same: clients retrieve issue details to inspect the variants and identify the matching cover. SKU matching remains case-insensitive and exact.

For example, both UPC 76194138788800621 and SKU 0625DC043 now find Absolute Martian Manhunter #6 through its Amy Reeder Cover B variant.

Updates the API documentation and adds regression tests using synthetic fixtures, independent of production or imported comic data.

Validation

222 tests passed, covering the new UPC/SKU cases and the existing issue API and website suites:

pytest tests/comicsdb/test_issue_sku_filters.py tests/comicsdb/test_issue_upc_filters.py tests/comicsdb/test_api_issue.py tests/comicsdb/test_issue_views.py --ds=metron.local_settings -o addopts= -q --reuse-db

metron.local_settings is an untracked local configuration selecting PostgreSQL and local caching. The tests themselves use the project's existing fixtures. The full repository test suite was not run.

Regression coverage includes main and variant matches, duplicate prevention, empty/no-match searches, combined filters, case-insensitive SKU matching, and rejection of partial SKU values. Also verified all five cover SKUs and both example UPCs against a locally running instance.

Checklist

  • Relevant tests pass locally (222 passed).
  • Ruff lint and format checks pass for all changed Python files.
  • Translation checklist: no templates, forms, or views changed; filter labels follow the existing plain-string convention. Translation catalogs were not regenerated.
  • Migration checklist: no models changed; no migrations required.

Extend API and website identifier filters to include variant covers without duplicate issues. Cover exact UPC/SKU and API UPC prefix searches with regression tests and document the behavior.

Refs Metron-Project#669
@bpepple

bpepple commented Nov 2, 2026

Copy link
Copy Markdown
Member

I'm pretty busy this week, but with some luck, I'll get a chance to look at this before the weekend.

@bpepple bpepple self-assigned this Nov 2, 2026

@bpepple bpepple left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, Eric! Matching variants on the exact upc and sku filters fixes a real gap. A variant's full 17-digit UPC (or its SKU) can never match the parent issue, so those covers couldn't be found before. I'd like to keep those changes.

I'd like to leave upc_starts_with as it was, though, matching only the main cover's UPC.

US direct-market comics usually give every cover of an issue the same 12-digit UPC-A. Only the 5-digit add-on changes (issue number, cover, printing). Using your example, 761941387888 + 00621, the main cover is …00611, so a 12-digit scan already finds the parent issue through its own UPC. A scanner that drops the add-on, which most mobile scanner libraries do, can't tell the covers apart anyway, so returning the parent issue is the best it can do, and it already does that today.

I checked this against a copy of the production data (~25k variants with UPCs):

  • ~24.5k variants share their parent's 12-digit base, so the variant branch finds nothing extra for them.
  • 84 variants belong to a parent with no UPC. The better fix there is to add the parent's UPC.
  • ~310 variants have a different base, and most of those are bad data (SKUs typed into the UPC field, typos, 18-digit UPCs). Prefix-matching on variants would mostly end up matching that bad data.

The join plus .distinct() also makes these lookups about 3× slower locally (~95 ms → ~280 ms). That's worth paying for the exact filters, but not for the prefix filter that scanner apps call most.

Could you make these changes?

  1. Change upc_starts_with back to a plain CharFilter on upc with lookup_expr="startswith", and revert its label and README text.
  2. In test_issue_upc_filters.py, drop the api_prefix param from the variant-only tests (test_upc_variant_cover_only sets up a parent and variant with entirely different bases, which doesn't really happen). If you want to keep prefix coverage, a test that a 12-digit prefix finds the parent through its main cover would be great.
  3. Update the README note so it says the variant matching applies to upc and sku only.

Everything else looks good. Thanks again!

@erickolb

erickolb commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for explaining the mobile scanner use case. No problem at all. Changes forthcoming presently.

Address maintainer feedback by restoring the original UPC prefix filter and documentation. Limit variant tests to exact lookups and cover 12-digit main-cover prefix searches separately.

Refs Metron-Project#670
@erickolb

erickolb commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

213 tests pass with the restored upc_starts_with behavior. Ready for re-review.

@erickolb
erickolb requested a review from bpepple November 3, 2026 14:40
The variant-only test gave the parent a UPC with an entirely different 12-digit base from its variant, which doesn't happen with direct-market comics. Use the main cover's UPC instead, so the parent and variant share the UPC-A and differ only in the 5-digit add-on. The full variant UPC still matches only through the variant. Also add readable parametrize IDs.

@bpepple bpepple left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, made a minor change to a test, but otherwise it's good. Thx!

@bpepple
bpepple merged commit 9b7070c into Metron-Project:master Nov 3, 2026
2 checks passed
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.

Variant UPC/SKU Searches Do Not Return the Parent Issue

2 participants