Skip to content

Document Cover Not Generated #1257

@sinjup

Description

@sinjup

Package version : invenio-app-ils 2.0.1+

Document covers are not being generated when creating new documents because the cover builder function only checks the cover_metadata field for ISBN, but ISBN is actually stored in the identifiers array. This results in all documents showing placeholder covers instead of actual book covers from Open Library.
The root cause is that the build_ils_demo_cover_urls() function in invenio_app_ils/literature/covers_builder.py doesn't check the identifiers array where ISBN is actually stored in document records.

Steps to Reproduce

  1. Create a new document via REST API with an ISBN in the identifiers array:
curl -X POST http://localhost:5000/api/documents \
  -H "Content-Type: application/json" \
  -d '{
    "title": "The Great Gatsby",
    "authors": [{"full_name": "F. Scott Fitzgerald"}],
    "document_type": "BOOK",
    "publication_year": "1925",
    "languages": ["eng"],
    "identifiers": [
      {
        "scheme": "ISBN",
        "value": "978-0-7432-7356-5"
      }
    ]
  }'
  1. Retrieve the created document:
curl -X GET http://localhost:5000/api/documents/{pid}
  1. Check the cover_metadata.urls field in the response

  2. See that is_placeholder is true and cover URLs point to placeholder image

Expected behavior

The document should have actual book cover URLs from Open Library:

{
  "cover_metadata": {
    "urls": {
      "is_placeholder": false,
      "small": "https://covers.openlibrary.org/b/isbn/978-0-7432-7356-5-S.jpg",
      "medium": "https://covers.openlibrary.org/b/isbn/978-0-7432-7356-5-M.jpg",
      "large": "https://covers.openlibrary.org/b/isbn/978-0-7432-7356-5-L.jpg"
    }
  }
}

Actual behavior

The document has placeholder cover URLs:

{
  "cover_metadata": {
    "urls": {
      "is_placeholder": true,
      "small": "http://localhost:5000/static/images/placeholder.png",
      "medium": "http://localhost:5000/static/images/placeholder.png",
      "large": "http://localhost:5000/static/images/placeholder.png"
    }
  }
}

Root Cause Analysis

File: invenio_app_ils/literature/covers_builder.py (line 16)

Current code:

def build_ils_demo_cover_urls(metadata):
    """Build working urls for demo data."""
    cover_metadata = metadata.get("cover_metadata", {})
    isbn = cover_metadata.get("ISBN", "")  # ❌ Only checks cover_metadata
    if isbn:
        return build_openlibrary_urls(isbn)
    return build_placeholder_urls()

The problem:

  • ISBN is stored in metadata["identifiers"] array with scheme: "ISBN"
  • Code only looks in cover_metadata field
  • Result: ISBN is never found, placeholder is always returned

Data structure in actual documents:

{
  "identifiers": [
    {
      "scheme": "ISBN",
      "value": "978-0-7432-7356-5"  // ← ISBN is HERE
    }
  ],
  "cover_metadata": {
    "urls": {}  // ← Code looks HERE (wrong place!)
  }
}

Proposed Solution

Update invenio_app_ils/literature/covers_builder.py to check the identifiers array:

def build_ils_demo_cover_urls(metadata):
    """Build working urls for demo data."""
    cover_metadata = metadata.get("cover_metadata", {})
    
    # First check cover_metadata for backward compatibility
    isbn = (
        cover_metadata.get("isbns", "") or 
        cover_metadata.get("ISBN", "") or
        ""
    )
    
    # Check identifiers array (where ISBN is actually stored)
    if not isbn:
        identifiers = metadata.get("identifiers", [])
        if identifiers:
            for identifier in identifiers:
                if identifier.get("scheme") == "ISBN":
                    isbn = identifier.get("value", "")
                    break
    
    if isbn:
        return build_openlibrary_urls(isbn)
    return build_placeholder_urls()

Additional context

Impact

  • Severity: High - Affects all document cover generation
  • Scope: All new documents created via API or demo data
  • User Impact: Library system shows placeholder covers instead of actual book covers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions