Skip to content

eval-cache: fix parsing of contexts#14879

Merged
tomberek merged 1 commit intoNixOS:masterfrom
ConnorBaker:fix/eval-cache-parsing-of-contexts
Dec 29, 2025
Merged

eval-cache: fix parsing of contexts#14879
tomberek merged 1 commit intoNixOS:masterfrom
ConnorBaker:fix/eval-cache-parsing-of-contexts

Conversation

@ConnorBaker
Copy link
Contributor

@ConnorBaker ConnorBaker commented Dec 28, 2025

Motivation

Fixing a small correctness bug -- the delimiter used for serialization and parsing should match.

Context

Storage of string contexts in the evaluation cache was introduced with 50f13b0. Currently it looks like:

AttrId setString(AttrKey key, std::string_view s, const Value::StringWithContext::Context * context = nullptr)
{
return doSQLite([&]() {
auto state(_state->lock());
if (context) {
std::string ctx;
bool first = true;
for (auto * elem : *context) {
if (!first)
ctx.push_back(' ');
ctx.append(elem->view());
first = false;
}
state->insertAttributeWithContext.use()(key.first)(symbols[key.second])(AttrType::String) (s) (ctx)
.exec();
} else {
state->insertAttribute.use()(key.first)(symbols[key.second])(AttrType::String) (s).exec();
}
return state->db.getLastInsertedRowId();
});
}

However, the delimiter used for parsing doesn't match:

case AttrType::String: {
NixStringContext context;
if (!queryAttribute.isNull(3))
for (auto & s : tokenizeString<std::vector<std::string>>(queryAttribute.getStr(3), ";"))
context.insert(NixStringContextElem::parse(s));
return {{rowId, string_t{queryAttribute.getStr(2), context}}};
}

Since this change doesn't modify the values written to the cache there's no need to bump the cache version.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

The members of the context were serialized with a space as the delimiter, not a semicolon.

Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
@ConnorBaker ConnorBaker self-assigned this Dec 28, 2025
@ConnorBaker ConnorBaker marked this pull request as ready for review December 28, 2025 15:55
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct, but it would be good for someone more familiar with the eval cache to double check

@tomberek tomberek added this pull request to the merge queue Dec 29, 2025
Merged via the queue into NixOS:master with commit b5e039b Dec 29, 2025
17 checks passed
@ConnorBaker ConnorBaker deleted the fix/eval-cache-parsing-of-contexts branch January 5, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants