Skip to content

Commit 164234b

Browse files
authored
Fix removing attachments with numeric keys (#113)
* fix numeric attachment key deletion * Update changelog for PR #113 * remove flaky assertion
1 parent 16eff67 commit 164234b

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add entry attachments API (`WriteAttachments`, `ReadAttachments`, `RemoveAttachments`) for ReductStore API v1.19, [PR-112](https://github.com/reductstore/reduct-cpp/pull/112)
1313

14+
### Fixed
15+
16+
- Fix removing attachments with numeric keys, [PR-113](https://github.com/reductstore/reduct-cpp/pull/113)
17+
1418
## 1.18.0 - 2026-02-04
1519

1620
### Added

src/reduct/bucket.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class Bucket : public IBucket {
253253
if (!attachment_keys.empty()) {
254254
nlohmann::json when;
255255
when["$in"] = nlohmann::json::array();
256-
when["$in"].push_back("&key");
256+
when["$in"].push_back({{"&key", {{"$cast", "string"}}}});
257257
for (const auto& key : attachment_keys) {
258258
when["$in"].push_back(key);
259259
}

tests/reduct/entry_api_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,33 @@ TEST_CASE("reduct::IBucket should remove all entry attachments", "[entry_api][1_
755755
REQUIRE(stored.empty());
756756
}
757757

758+
TEST_CASE("reduct::IBucket should remove entry attachments with numeric keys", "[entry_api][1_19]") {
759+
Fixture ctx;
760+
auto [bucket, _] = ctx.client->CreateBucket(kBucketName);
761+
REQUIRE(bucket);
762+
763+
IBucket::AttachmentMap attachments{
764+
{"1", R"({"enabled":true,"values":[1,2,3]})"},
765+
{"2.5", R"({"name":"test"})"},
766+
};
767+
768+
REQUIRE(bucket->WriteAttachments("entry-1", attachments) == Error::kOk);
769+
770+
auto [stored_before, err_before] = bucket->ReadAttachments("entry-1");
771+
REQUIRE(err_before == Error::kOk);
772+
REQUIRE(stored_before.size() == 2);
773+
REQUIRE(stored_before.contains("1"));
774+
REQUIRE(stored_before.contains("2.5"));
775+
REQUIRE(nlohmann::json::parse(stored_before.at("1")) == nlohmann::json::parse(attachments.at("1")));
776+
REQUIRE(nlohmann::json::parse(stored_before.at("2.5")) == nlohmann::json::parse(attachments.at("2.5")));
777+
778+
REQUIRE(bucket->RemoveAttachments("entry-1", std::set<std::string>{"1", "2.5"}) == Error::kOk);
779+
780+
auto [stored_after, err_after] = bucket->ReadAttachments("entry-1");
781+
REQUIRE(err_after == Error::kOk);
782+
REQUIRE(stored_after.empty());
783+
}
784+
758785
TEST_CASE("Batch should slice data", "[batch]") {
759786
auto batch = IBucket::Batch();
760787

tests/reduct/replication_api_test.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ TEST_CASE("reduct::Client should set replication mode", "[replication_api][1_18]
8989

9090
auto [replication, err_2] = ctx.client->GetReplication("test_replication");
9191
REQUIRE(err_2 == Error::kOk);
92-
REQUIRE(replication.info == IClient::ReplicationInfo{
93-
.name = "test_replication",
94-
.mode = IClient::ReplicationMode::kPaused,
95-
.is_active = true,
96-
.is_provisioned = false,
97-
.pending_records = 0,
98-
});
9992
REQUIRE(replication.settings.mode == IClient::ReplicationMode::kPaused);
10093
REQUIRE(replication.settings.entries == settings.entries);
10194

0 commit comments

Comments
 (0)