{"record":{"id":"51eb01144f73e3b3","repo":"PaddlePaddle/PaddleOCR","slug":"second-argument-needs-to-be-a-s","errorCode":null,"errorMessage":"Second argument needs to be a %s","messagePattern":"Second argument needs to be a (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppstructure/recovery/table_process.py","lineNumber":219,"sourceCode":"    def get_tables(self):\n        if not hasattr(self, \"soup\"):\n            self.include_tables = False\n            return\n            # find other way to do it, or require this dependency?\n        self.tables = self.ignore_nested_tables(self.soup.find_all(\"table\"))\n        self.table_no = 0\n\n    def run_process(self, html):\n        if self.bs and BeautifulSoup:\n            self.soup = BeautifulSoup(html, \"html.parser\")\n            html = str(self.soup)\n        if self.include_tables:\n            self.get_tables()\n        self.feed(html)\n\n    def add_html_to_cell(self, html, cell):\n        if not isinstance(cell, docx.table._Cell):\n            raise ValueError(\"Second argument needs to be a %s\" % docx.table._Cell)\n        unwanted_paragraph = cell.paragraphs[0]\n        if unwanted_paragraph.text == \"\":\n            delete_paragraph(unwanted_paragraph)\n        self.set_initial_attrs(cell)\n        self.run_process(html)\n        # cells must end with a paragraph or will get message about corrupt file\n        # https://stackoverflow.com/a/29287121\n        if not self.doc.paragraphs:\n            self.doc.add_paragraph(\"\")\n\n    def apply_paragraph_style(self, style=None):\n        try:\n            if style:\n                self.paragraph.style = style\n            elif self.paragraph_style:\n                self.paragraph.style = self.paragraph_style\n        except KeyError as e:\n            raise ValueError(f\"Unable to apply style {self.paragraph_style}.\") from e","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppstructure/recovery/table_process.py#L201-L237","documentation":"Raised by TableToDocx (htmldocx-derived) in add_html_to_cell when the second argument is not a python-docx _Cell object. Before writing HTML content into a table cell, the parser verifies the target is a real docx cell so it can safely access cell.paragraphs and cell styles. Passing a merged-cell placeholder, a Table object, or None triggers it. The message interpolates the class object itself, so it prints like \"<class 'docx.table._Cell'>\".","triggerScenarios":"Calling table_parser.add_html_to_cell(html, cell) where cell is not an instance of docx.table._Cell — e.g. a docx.table.Table, a string, or a cell obtained from an API that returned a different type.","commonSituations":"Custom table-recovery code that iterates a docx table and passes rows/tables instead of cells; handling merged cells where code indexes cell.tc_pr or substitutes None; version drift in python-docx where _Cell is imported from a different module path.","solutions":["Pass an actual cell object: doc.add_table(...).rows[r].cells[c]","If the target may be a merged span, resolve it via table.cell(r, c) which returns the spanning _Cell","Add an isinstance check upstream and skip/handle non-cell targets instead of letting the parser raise"],"exampleFix":"# before\nparser.add_html_to_cell(html, doc.tables[0].rows[0])  # a _Row, not a _Cell\n\n# after\nrow = doc.tables[0].rows[0]\nfor cell in row.cells:\n    parser.add_html_to_cell(html, cell)","handlingStrategy":"type-guard","validationCode":"import docx.table\nif not isinstance(cell, docx.table._Cell):\n    raise TypeError(f'expected _Cell, got {type(cell).__name__}')\nparser.add_html_to_cell(html, cell)","typeGuard":"import docx.table\n\ndef is_docx_cell(obj) -> bool:\n    \"\"\"True when obj is a python-docx table cell.\"\"\"\n    return isinstance(obj, docx.table._Cell)","tryCatchPattern":"try:\n    parser.add_html_to_cell(html, cell)\nexcept ValueError as e:\n    if 'needs to be a' in str(e):\n        raise TypeError(f'bad cell target: {type(cell).__name__}') from e\n    raise","preventionTips":["Always obtain cells via table.cell(r, c) or row.cells[c], never pass rows/tables","Type-annotate cell parameters as docx.table._Cell so mypy catches misuse"],"tags":["docx","table-recovery","type-mismatch","ppstructure"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}