Skip to content

Commit dc37c17

Browse files
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.
1 parent 3755e3f commit dc37c17

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

plugins/python/parser/include/pythonparser/pythonparser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class PythonParser : public AbstractParser
2626
PythonParser(ParserContext& ctx_);
2727
virtual ~PythonParser();
2828
virtual bool parse() override;
29+
virtual bool cleanupDatabase() override;
2930
private:
3031
struct ParseResultStats {
3132
std::uint32_t partial;

plugins/python/parser/src/pythonparser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ bool PythonParser::parse()
182182
return true;
183183
}
184184

185+
bool PythonParser::cleanupDatabase()
186+
{
187+
LOG(info) << "[pythonparser] Incremental parsing unsupported, cleaning up previous analysis results from database ...";
188+
odb::connection_ptr connection = _ctx.db->connection();
189+
#ifdef DATABASE_PGSQL
190+
connection->execute("TRUNCATE TABLE \"PYName\";");
191+
#else
192+
connection->execute("DELETE FROM \"PYName\";");
193+
#endif
194+
LOG(info) << "[pythonparser] Cleanup finished!";
195+
return true;
196+
}
197+
185198
PythonParser::~PythonParser()
186199
{
187200
}

0 commit comments

Comments
 (0)