Skip to content

Commit b7478e3

Browse files
Fix missing check for constant components (#1776)
* Add missing check * Fix test
1 parent d4f3e2a commit b7478e3

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/RecordComponent.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void RecordComponent::flush(
272272
{
273273
// The check for !written() is technically not needed, just
274274
// defensive programming against internal bugs that go on us.
275-
if (!written() && rc.m_chunks.empty())
275+
if (!written() && rc.m_chunks.empty() && !rc.m_isConstant)
276276
{
277277
// No data written yet, just accessed the object so far without
278278
// doing anything
@@ -283,7 +283,8 @@ void RecordComponent::flush(
283283
{
284284
throw error::WrongAPIUsage(
285285
"[RecordComponent] Must specify dataset type and extent "
286-
"before flushing (see RecordComponent::resetDataset()).");
286+
"before flushing or setting a constant value (see "
287+
"RecordComponent::resetDataset()).");
287288
}
288289
}
289290
if (!containsAttribute("unitSI"))

test/python/unittest/API/APITest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def refcountingCreateData(self):
109109
for dim in ["x", "y"]:
110110
# Do not bother with a positionOffset
111111
position_offset = e["positionOffset"][dim]
112+
position_offset.reset_dataset(
113+
io.Dataset(np.dtype("int"), [100]))
112114
position_offset.make_constant(0)
113115

114116
position = e["position"][dim]

0 commit comments

Comments
 (0)