diff --git a/dbms/src/TiDB/Schema/SchemaGetter.cpp b/dbms/src/TiDB/Schema/SchemaGetter.cpp index 60a39d54044..9162e18dd75 100644 --- a/dbms/src/TiDB/Schema/SchemaGetter.cpp +++ b/dbms/src/TiDB/Schema/SchemaGetter.cpp @@ -172,7 +172,10 @@ void SchemaDiff::deserialize(const String & data) old_table_id = obj->getValue("old_table_id"); old_schema_id = obj->getValue("old_schema_id"); - regenerate_schema_map = obj->getValue("regenerate_schema_map"); + if (obj->has("regenerate_schema_map")) + { + regenerate_schema_map = obj->getValue("regenerate_schema_map"); + } affected_opts.clear(); auto affected_arr = obj->getArray("affected_options"); diff --git a/dbms/src/TiDB/Schema/tests/gtest_schema_sync.cpp b/dbms/src/TiDB/Schema/tests/gtest_schema_sync.cpp index 8acf2c22e62..29c16a9015d 100644 --- a/dbms/src/TiDB/Schema/tests/gtest_schema_sync.cpp +++ b/dbms/src/TiDB/Schema/tests/gtest_schema_sync.cpp @@ -39,7 +39,6 @@ extern const char force_context_path[]; } // namespace FailPoints namespace tests { - class SchemaSyncTest : public ::testing::Test { public: @@ -179,6 +178,17 @@ class SchemaSyncTest : public ::testing::Test Context & global_ctx; }; +TEST_F(SchemaSyncTest, SchemaDiff) +try +{ + // Note that if we want to add new fields here, please firstly check if it is present. + // Otherwise it will break when doing upgrading test. + SchemaDiff diff; + std::string data = "{\"version\":40,\"type\":31,\"schema_id\":69,\"table_id\":71,\"old_table_id\":0,\"old_schema_id\":0,\"affected_options\":null}"; + ASSERT_NO_THROW(diff.deserialize(data)); +} +CATCH + TEST_F(SchemaSyncTest, RenameTables) try {