Skip to content

Don't save number of pages 0 from Amazon #10888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

cdrini
Copy link
Collaborator

@cdrini cdrini commented Jun 2, 2025

Closes #10868 . Small fix, just check if 0.

Technical

Testing

Tested via unit tests; couldn't test this otherwise since the already-coerced metadata record is stored in the affiliate server cache, so can't have it be re-processed by my new code.

Screenshot

Stakeholders

@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 21:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that books with zero pages from Amazon don’t include a number_of_pages field in the serialized output.

  • Add a unit test to verify pages count of 0 is omitted.
  • Update serialize to skip number_of_pages when its value is zero.
  • Adjust existing test to no longer expect an empty number_of_pages key.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
openlibrary/tests/core/test_vendors.py Add test for zero pages and remove outdated expectation
openlibrary/core/vendors.py Change serialization to omit number_of_pages when zero
Comments suppressed due to low confidence (1)

openlibrary/core/vendors.py:323

  • Relying on truthiness to exclude zero works for numeric values but could include '0' if display_value were ever a string. Consider explicitly checking edition_info.pages_count.display_value > 0.
and edition_info.pages_count.display_value

Comment on lines +317 to +325
**(
{'number_of_pages': edition_info.pages_count.display_value}
if (
edition_info
and edition_info.pages_count
# Note this intentionally excludes 0
and edition_info.pages_count.display_value
)
else {}
Copy link
Preview

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

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

[nitpick] The dictionary-unpacking with **({ ... }) adds complexity. Consider building the number_of_pages key directly in the surrounding dict (e.g., using a single conditional assignment) to improve readability.

Suggested change
**(
{'number_of_pages': edition_info.pages_count.display_value}
if (
edition_info
and edition_info.pages_count
# Note this intentionally excludes 0
and edition_info.pages_count.display_value
)
else {}
'number_of_pages': (
edition_info.pages_count.display_value
if (
edition_info
and edition_info.pages_count
# Note this intentionally excludes 0
and edition_info.pages_count.display_value
)
else None

Copilot uses AI. Check for mistakes.

@mekarpeles mekarpeles merged commit 1f117ab into internetarchive:master Jun 9, 2025
4 checks passed
@cdrini cdrini deleted the 10868/fix/amazon-0-pages branch June 9, 2025 23:04
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.

Invalid page count imported from amazon
2 participants