Skip to content

fix: skip standalone chartsheets in practice XLSX import - #3248

Open
JsSun-1000001000 wants to merge 2 commits into
HKUDS:devfrom
JsSun-1000001000:fix/practice-xlsx-chartsheet
Open

JsSun-1000001000 wants to merge 2 commits into
HKUDS:devfrom
JsSun-1000001000:fix/practice-xlsx-chartsheet

Conversation

@JsSun-1000001000

@JsSun-1000001000 JsSun-1000001000 commented Dec 4, 2026 •

Copy link
Copy Markdown

Description

Fix an unhandled AttributeError (HTTP 500) in POST /api/question-notebook/practice/import/preview when importing a valid .xlsx workbook whose active tab is a standalone Chartsheet.

In deeptutor/services/practice/importing.py (parse_rows), book.active can be a Chartsheet, which has neither max_column nor iter_rows(). When book.active is None or not in book.worksheets, this change falls back to book.worksheets[0] if present; otherwise it raises ValueError("The workbook has no active worksheet") so the router returns HTTP 422 instead of HTTP 500. Multi-worksheet workbooks with a non-first active worksheet continue to read the active worksheet as before.

Related Issues

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • This PR targets dev (not main — see the base-branch selector above).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

Verification

  • pytest -q tests/api/test_practice.py → 50 passed (includes new regressions covering active chartsheet before/after a data worksheet, chart-only workbook returning HTTP 422 instead of 500, and multi-worksheet active tab preservation).
  • ruff check ., ruff format --check ., lint-imports, python scripts/check_architecture.py, and python scripts/check_repo_hygiene.py all passed.
  • pre-commit run --all-files: 14/15 hooks passed across the repo (the only error was a pre-existing Windows-only mypy stub check on unrelated deeptutor/services/subagent/models.py:298); all hooks including mypy passed on the modified files during commit.
  • Manually verified in the local Web UI (/learning/practice → Import): uploading a workbook with an active standalone chartsheet now succeeds with HTTP 200 and previews the questions, and a chart-only workbook returns HTTP 422 cleanly.
bf0887082eab4596d8ceed9194adbfc7 2333ea21bf73dfd43d801d087e7ef02b

@github-actions github-actions Bot added backend Python runtime, capabilities, tools, API & CLI bug Something isn't working labels Dec 4, 2026
@JsSun-1000001000

JsSun-1000001000 commented Dec 4, 2026 •

Copy link
Copy Markdown
Author

Root-cause analysis of the Python Tests (Python 3.13) failure

The only failing check in this PR is tests/services/test_github_copilot_auth.py::test_web_auth_service_device_flow_lifecycle (AssertionError: assert 2 == 1 at line 255), which is an unrelated async timing race in the test rather than a regression from this PR:

  1. In tests/services/test_github_copilot_auth.py:236, asyncio.sleep is patched to return immediately (_immediate()), and the mock _Client resolves device polling in memory after 2 calls without I/O delay.
  2. The first await service.start_login() (:242) schedules _poll_device_flow() via loop.create_task(...) (deeptutor/services/github_copilot_auth.py:703) and yields to the event loop in await self.status() (:718) and again at the start of the second start_login() in await asyncio.to_thread(self._storage.reserve_device_flow) (:624).
  3. When the worker thread takes slightly longer on a busy runner, the zero-delay _poll_device_flow() finishes both polls and completes/clears the pending flow before the second reserve_device_flow() runs, causing the second start_login() (:250) to start a fresh flow and send a second POST /device/code.

All 15,436 other tests on Python 3.13 (including all practice import tests) as well as Python 3.11 / 3.12 / 3.14 and all other 22 CI checks passed. Could a maintainer please re-run the failed job?

@MohammadHijjawi97 MohammadHijjawi97 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.

Verified locally on Windows, Python 3.13 with openpyxl from requirements/dev.txt:

  • tests/api/test_practice.py: 50 passed on this head.
  • With deeptutor/services/practice/importing.py reverted to dev and the new test kept, it fails with AttributeError: 'Chartsheet' object has no attribute 'max_column', the 500 from #3247. So the test catches the bug.
  • Ruff check and format on both changed files are clean.

The identity check (ws is sheet against book.worksheets) also works in read_only=True mode. The multi-sheet case in the test, with the second worksheet active, still reads the active sheet.

The red Python Tests (3.13) check here is the Copilot device-flow flake (assert 2 == 1), not this change. #3254 fixes it, and I reproduced that separately.

This branch has not been deployed

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

Labels

backend Python runtime, capabilities, tools, API & CLI bug Something isn't working

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants