Skip to content

Commit 548a7ec

Browse files
natoscottclaude
andcommitted
pcp.pmi: fix pmiWrite when sec=0 and usec is omitted
The condition 'if sec and not usec' fails when sec==0 because 0 is falsy, leaving usec as None and causing pmiWrite2(0, None) to raise TypeError against its c_int argtypes. Change to 'if usec is None' so the datetime/float dispatch and the usec=0 fallback always run when usec was not supplied by the caller. Add a pmiWrite(0) call at the start of qa/src/test_pmi.python to cover this path, and update qa/708.out accordingly. Signed-off-by: Nathan Scott <nathans@redhat.com> Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ea0b38 commit 548a7ec

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

qa/708.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pmiSetTimezone: UTC
55
pmid 251.1.1
66
units
77
pmiAddMetric: qa.one
8+
pmiPutValue: qa.one (epoch)
89
pmiPutValue: qa.one
910
pmid 251.1.2
1011
indom 251.3
@@ -26,7 +27,7 @@ Note: timezone set to local timezone of host "fu.bar.com" from archive
2627
qa.one
2728
Data Type: 32-bit unsigned int InDom: PM_INDOM_NULL 0x........
2829
Semantics: discrete Units: none
29-
value 42
30+
value 1
3031

3132
qa.two
3233
Data Type: float InDom: 251.3 0x........

qa/src/test_pmi.python

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def test_pmi(self, path = OUTFILE, inherit = 0):
5252
print("pmiAddMetric: qa.one")
5353
self.assertTrue(code >= 0)
5454

55+
# exercise pmiWrite(0) - sec=0 with no usec previously raised TypeError
56+
code = log.pmiPutValue("qa.one", "", "1")
57+
print("pmiPutValue: qa.one (epoch)")
58+
self.assertTrue(code >= 0)
59+
log.pmiWrite(0)
60+
5561
# give it a value
5662
code = log.pmiPutValue("qa.one", "", "42")
5763
print("pmiPutValue: qa.one")

src/python/pcp/pmi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def pmiWrite(self, sec: Union[int, float, datetime],
386386
status = LIBPCP_IMPORT.pmiUseContext(self._ctx)
387387
if status < 0:
388388
raise pmiErr(status)
389-
if sec and not usec:
389+
if usec is None:
390390
if isinstance(sec, datetime):
391391
sec = float((sec - self._epoch).total_seconds())
392392
if isinstance(sec, float):

0 commit comments

Comments
 (0)