Commit 0d4fc48c authored by Jan Reimes's avatar Jan Reimes
Browse files

🐛 fix(ai): handle ValueError in LanceDB table lookup

parent 8735c517
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -398,8 +398,9 @@ class AiStorage:
            else:
                self._tables[name] = existing_table
            return
        except FileNotFoundError:
        except FileNotFoundError, ValueError:
            # Table doesn't exist, continue to create it
            # ValueError is raised by LanceDB when table not found
            pass

        # Create the table, handling race condition where it might be created
@@ -414,11 +415,11 @@ class AiStorage:
            else:
                raise

    def _table(self, name: str) -> LanceDBTable:
    def _table(self, name: str) -> Any:
        return self._tables[name]


def _table_to_records(table: LanceDBTable) -> list[dict[str, Any]]:
def _table_to_records(table: Any) -> list[dict[str, Any]]:
    try:
        dataframe = table.to_pandas()
        return dataframe.to_dict("records")
+2 −6
Original line number Diff line number Diff line
@@ -294,14 +294,9 @@ class TDocDatabase(MeetingDatabase):
            # Query all required fields from actual database schema
            with sqlite3.connect(self.connection.filename) as conn:
                cursor = conn.cursor()
                cursor.execute(
                    "SELECT tdoc_id, meeting_id, title, url, source, contact, agenda_item_nbr "
                    "FROM tdocs WHERE tdoc_id = ?",
                    (tdoc_id.upper(),)
                )
                cursor.execute("SELECT tdoc_id, meeting_id, title, url, source, contact, agenda_item_nbr FROM tdocs WHERE tdoc_id = ?", (tdoc_id.upper(),))
                row = cursor.fetchone()
                if row:
                    from tdoc_crawler.tdocs.models import TDocMetadata
                    return TDocMetadata(
                        tdoc_id=row[0],
                        meeting_id=row[1],
@@ -314,6 +309,7 @@ class TDocDatabase(MeetingDatabase):
                return None
        except sqlite3.Error:
            return None

    # ------------------------------------------------------------------
    # Normalisation helpers
    # ------------------------------------------------------------------