Skip to content

[Bug]: Practice XLSX import returns 500 when the active tab is a standalone Chartsheet #3247

Backlog

Description

@JsSun-1000001000

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

Uploading a valid .xlsx workbook to POST /api/question-notebook/practice/import/preview fails with HTTP 500 (AttributeError: 'Chartsheet' object has no attribute 'max_column') whenever the workbook's active tab is a standalone chartsheet — even if the workbook contains valid question worksheets.

Root cause:

  • deeptutor/services/practice/importing.py (parse_rows) reads sheet = book.active and immediately accesses sheet.max_column and sheet.iter_rows().
  • In openpyxl, book.active can be a Chartsheet (which has neither max_column nor iter_rows()).
  • deeptutor/api/routers/practice.py (import_preview) converts ValueError and known archive/parse errors to HTTP 422, so the unhandled AttributeError surfaces as an HTTP 500.

This is the same class of openpyxl chartsheet issue previously fixed for chat attachment extraction in #2817 / #2960.

Steps to reproduce

  1. Create a valid .xlsx workbook with a standalone chartsheet tab set as active and a normal worksheet tab containing valid practice questions (or a chart-only workbook).
  2. Open /learning/practice → Import, and upload the .xlsx file (calling POST /api/question-notebook/practice/import/preview).
  3. Observe HTTP 500 in browser DevTools (Network) and AttributeError: 'Chartsheet' object has no attribute 'max_column' in backend logs.
  4. I have a focused fix and regression tests ready and will open a PR targeting dev shortly.

Expected Behavior

  • If book.active is a normal worksheet, continue reading it as before.
  • If book.active is a Chartsheet (not in book.worksheets), fall back to the first worksheet (book.worksheets[0]) and preview its questions (HTTP 200).
  • If the workbook has no ordinary worksheets at all (chart-only), raise ValueError("The workbook has no active worksheet") so the API returns HTTP 422 instead of HTTP 500.

Related Module

API/Backend

Configuration Used

No response

Logs and screenshots

image

Additional Information

Activity

  1. added
    bug
    on Dec 4, 2026
  2. added
    backend
    has logs
    on Dec 4, 2026
  3. Qiuner commented on Dec 4, 2026

    @Qiuner
    Collaborator

    Thanks for the clear reproduction. #3248 covers the practice import path, including falling back to a normal worksheet and returning a validation error for chart-only files. #2817 covers chat attachments, so the two reports track separate import paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbughas logs

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions