fix(attribute): persist inherited default-backed attribute updates
What this does
An attribute that a node inherits from a generic and that carries a schema default now persists a written value even when the node predates the inheritance. Writing a non-default value to such an attribute materialises its database row on save, so the value survives a reload, gains a real id, and is no longer flagged as the default.
Closes #9284.
Root cause (history)
The bug is a chain, and its origin is a previous fix:
- An attribute inherited from a generic lives on the generic, not on each concrete node. Nodes created before their schema started inheriting the generic therefore have no database row for the attribute.
- #7408 (
03f7…, prep 1.10.0 era) made the add-attribute migration a no-op for inherited attributes to stop duplicate rows being created on nodes that already inherited the generic. That fix was correct for those nodes, but it removed the only path — the node-kind–matched migration — that used to materialise a row for pre-existing instances. Those nodes were left with no row. - The attribute save path bailed out on any attribute without an id (
if not self.id: return None), so a write to a rowless inherited attribute was silently dropped.
So #7408 fixed a duplicate-row bug for already-inheriting nodes and, as a side effect, opened this persistence gap for nodes that predate the inheritance. This branch closes the write side of that gap.
The change
save()now materialises the missing row on the first non-default write, then reconciles the value andis_defaultthrough the regular update path. Two guards keep it safe: it stays virtual when the value equals the default, and it does not create a second row when one already exists (e.g. an attribute rebuilt without its id).- The materialisation query is shared with the schema migration rather than duplicated.
AttributeAddQuerywas relocated tocore/queryand generalised to optionally target specific node uuids; the ~100-line near-duplicate that the first cut of the fix introduced was removed. - Two correctness fixes surfaced by code review: the changelog now reports the schema default as the previous value (it was being read back from the transient placeholder row), and materialisation matches the node by its own kind label, so it also reaches Profile / Template / Schema-namespace nodes rather than only
Node-labelled ones.
Known limitation — residual read-side gap
The fix restores writes, not queryability at the default. A node that predates the inheritance and still holds the default has no value row, so an attribute-value filter on that default does not match it until a value is written and the row is materialised. This is captured by an xfail(strict=True) test that asserts the desired behaviour, so it flips to a failure the day the gap is closed.
Alternative considered — Solution B (root-cause fix)
Instead of materialising lazily on write, the structurally correct fix would act at the migration / schema-evolution layer: when a node starts inheriting a generic, materialise (or relabel) the rows for existing instances so the single generic-migration path covers them. That would:
- remove the need for any materialisation logic in
save(), and - close the residual queryability gap above (every node would carry a real default row).
It is heavier and touches the migration layer, so it was not taken here. This branch keeps the smaller, save-side fix and shares one query instead of duplicating it. Solution B is the recommended follow-up if the team wants default-value queryability restored.
🤖 Generated with Claude Code