From dc37c17415eb451c671463fbc60ee32fe46a6540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20Domozi?= Date: Mon, 9 Mar 2026 23:08:55 +0100 Subject: [PATCH] Fix Python plugin project reparse Currently, if we try to reparse a Python project, the CodeCompass_parser exits with the following error: "terminate called after throwing an instance of 'odb::object_already_persistent'". As a fix, we perform a database cleanup in case of incremental parsing. Note: incremental parsing is not intended to work this way and should be implemented properly in the future. --- .../parser/include/pythonparser/pythonparser.h | 1 + plugins/python/parser/src/pythonparser.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/python/parser/include/pythonparser/pythonparser.h b/plugins/python/parser/include/pythonparser/pythonparser.h index b3b1c25d8..79ce39ea3 100644 --- a/plugins/python/parser/include/pythonparser/pythonparser.h +++ b/plugins/python/parser/include/pythonparser/pythonparser.h @@ -26,6 +26,7 @@ class PythonParser : public AbstractParser PythonParser(ParserContext& ctx_); virtual ~PythonParser(); virtual bool parse() override; + virtual bool cleanupDatabase() override; private: struct ParseResultStats { std::uint32_t partial; diff --git a/plugins/python/parser/src/pythonparser.cpp b/plugins/python/parser/src/pythonparser.cpp index f52c8703b..3f3125b43 100644 --- a/plugins/python/parser/src/pythonparser.cpp +++ b/plugins/python/parser/src/pythonparser.cpp @@ -182,6 +182,19 @@ bool PythonParser::parse() return true; } +bool PythonParser::cleanupDatabase() +{ + LOG(info) << "[pythonparser] Incremental parsing unsupported, cleaning up previous analysis results from database ..."; + odb::connection_ptr connection = _ctx.db->connection(); +#ifdef DATABASE_PGSQL + connection->execute("TRUNCATE TABLE \"PYName\";"); +#else + connection->execute("DELETE FROM \"PYName\";"); +#endif + LOG(info) << "[pythonparser] Cleanup finished!"; + return true; +} + PythonParser::~PythonParser() { }