SysrepoAccess: Fix overwriting leafs without commit
Bug: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/229
Change-Id: Ia63b2ba5b91020108d8d1c64aa5db7cafa969f69
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 30a3e25..bbdf6d1 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -140,7 +140,7 @@
{
try {
m_session->session_switch_ds(targetToDs_set(m_target));
- m_session->set_item(path.c_str(), boost::apply_visitor(valFromValue(), value));
+ m_session->set_item(path.c_str(), boost::apply_visitor(valFromValue(), value), SR_EDIT_ISOLATE);
} catch (sysrepo::sysrepo_exception& ex) {
reportErrors();
}
diff --git a/tests/datastore_access.cpp b/tests/datastore_access.cpp
index 76e4f7f..bbcae25 100644
--- a/tests/datastore_access.cpp
+++ b/tests/datastore_access.cpp
@@ -222,6 +222,17 @@
REQUIRE(datastore.getItems("/example-schema:leafString") == expected);
}
+ SECTION("set a string, then set it to something else without commiting")
+ {
+ REQUIRE_CALL(mockRunning, write("/example-schema:leafString", std::nullopt, "oops"s));
+ datastore.setLeaf("/example-schema:leafString", "blah"s);
+ datastore.setLeaf("/example-schema:leafString", "oops"s);
+ datastore.commitChanges();
+ DatastoreAccess::Tree expected{{"/example-schema:leafString", "oops"s}};
+ REQUIRE(datastore.getItems("/example-schema:leafString") == expected);
+
+ }
+
SECTION("set a non-existing leaf")
{
catching<OnInvalidSchemaPathCreate>([&] {