Skip to content

Fix KeyError in promise_batch_imports.py script#12835

Merged
mekarpeles merged 2 commits into
masterfrom
promise-item-key-error-fixup
Jul 1, 2026
Merged

Fix KeyError in promise_batch_imports.py script#12835
mekarpeles merged 2 commits into
masterfrom
promise-item-key-error-fixup

Conversation

@jimchamp

@jimchamp jimchamp commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

The promise item cron job is sometimes failing with a KeyError when attempting to access the sku in a promise item record. This occurs within the map_book_to_olbook function.

This branch updates the code to use the get method to access this data. If a sku is not found, the promise item's json is logged, and None is returned by map_book_to_olbook.

Technical

Testing

Screenshot

Stakeholders

Copilot AI review requested due to automatic review settings June 1, 2026 21:03

Copilot AI 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.

Pull request overview

Fixes a KeyError in the promise_batch_imports.py cron job by switching from bracket indexing to .get() lookups when extracting the SKU fields from a promise item record, and gracefully skipping records that lack any SKU.

Changes:

  • Use dict.get() for BookSKUB, BookSKU, and BookBarcode in map_book_to_olbook, logging and returning None when no SKU is found.
  • Filter out None results from the generator passed into batch_import using an assignment expression.

Comment thread scripts/promise_batch_imports.py
@mekarpeles mekarpeles self-assigned this Jun 8, 2026
@mekarpeles mekarpeles merged commit 0760d99 into master Jul 1, 2026
8 checks passed
@mekarpeles mekarpeles deleted the promise-item-key-error-fixup branch July 1, 2026 16:32
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.

3 participants