Skip to content

write/point: run convertField when AddField re-sets an existing key - #428

Open
c-tonneslan wants to merge 1 commit into
influxdata:masterfrom
c-tonneslan:fix/addfield-convert-on-update
Open

c-tonneslan wants to merge 1 commit into
influxdata:masterfrom
c-tonneslan:fix/addfield-convert-on-update

Conversation

@c-tonneslan

Copy link
Copy Markdown

Found while reading api/write/point.go.

AddField runs the input value through convertField when appending a new field, so e.g. int32(5) lands in the point as int64(5), a time.Time as its RFC3339Nano string, etc. But the re-set path on the existing key did:

m.fields[i].Value = v

with the raw v. So the canonical-type guarantee quietly disappeared on update. Easiest to see with non-int64 ints, where the line-protocol encoder downstream expects int64:

p := NewPointWithMeasurement("m")
p.AddField("x", int32(1))   // stored as int64(1) via convertField
p.AddField("x", int32(2))   // stored as int32(2)  !!

Pulled the convertField call out front so both branches use the same value. Added a regression test on the int32 case.

Adding a field for the first time goes through convertField (so an
int32(5) lands as int64(5), a time.Time as its RFC3339Nano string, etc).
Re-setting the same key did m.fields[i].Value = v with the raw input, so
the canonical-type guarantee silently disappeared on update. Easiest to
see with non-int64 ints, where the line-protocol encoder downstream
expects int64.

Pulled convertField out front so both branches use the same value.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@codecov-commenter

codecov-commenter commented May 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.99%. Comparing base (67f504e) to head (30aacbc).
⚠️ Report is 10 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #428   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files          25       25           
  Lines        2326     2327    +1     
=======================================
+ Hits         2163     2164    +1     
  Misses        123      123           
  Partials       40       40           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants