Skip to content

Commit 0994c8d

Browse files
committed
Ensure no field value is null
Fix issue #2420.
1 parent 73a5747 commit 0994c8d

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [#2415](https://github.com/influxdb/influxdb/pull/2415): Raft leader ID now set on election after failover. Thanks @xiaost
1010
- [#2426](https://github.com/influxdb/influxdb/pull/2426): Fix race condition around listener address in openTSDB server.
1111
- [#2426](https://github.com/influxdb/influxdb/pull/2426): Fix race condition around listener address in Graphite server.
12+
- [#2429](https://github.com/influxdb/influxdb/pull/2429): Ensure no field value is null.
1213

1314
### Features
1415
- [#2410](https://github.com/influxdb/influxdb/pull/2410) Allow configuration of Raft timers

httpd/handler_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,26 @@ func TestHandler_serveWriteSeriesWithNoFields(t *testing.T) {
11841184
}
11851185
}
11861186

1187+
func TestHandler_serveWriteSeriesWithNullFields(t *testing.T) {
1188+
c := test.NewDefaultMessagingClient()
1189+
defer c.Close()
1190+
srvr := OpenAuthenticatedServer(c)
1191+
srvr.CreateDatabase("foo")
1192+
srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar"))
1193+
s := NewAPIServer(srvr)
1194+
defer s.Close()
1195+
1196+
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "fields": {"country": null}}]}`)
1197+
1198+
expected := fmt.Sprintf(`{"error":"%s"}`, influxdb.ErrFieldIsNull.Error())
1199+
1200+
if status != http.StatusInternalServerError {
1201+
t.Fatalf("unexpected status: %d", status)
1202+
} else if body != expected {
1203+
t.Fatalf("result mismatch:\n\texp=%s\n\tgot=%s\n", expected, body)
1204+
}
1205+
}
1206+
11871207
func TestHandler_serveWriteSeriesWithAuthNilUser(t *testing.T) {
11881208
c := test.NewDefaultMessagingClient()
11891209
defer c.Close()

influxdb.go

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ var (
117117
// ErrFieldsRequired is returned when a point does not any fields.
118118
ErrFieldsRequired = errors.New("fields required")
119119

120+
// FieldIsNull is returned when one of a point's field is null.
121+
ErrFieldIsNull = errors.New("field value is null")
122+
120123
// ErrFieldOverflow is returned when too many fields are created on a measurement.
121124
ErrFieldOverflow = errors.New("field overflow")
122125

server.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1766,11 +1766,17 @@ func (s *Server) WriteSeries(database, retentionPolicy string, points []Point) (
17661766
database, retentionPolicy, len(points))
17671767
}
17681768

1769-
// Make sure every point has at least one field.
1769+
// Make sure every point is valid.
17701770
for _, p := range points {
17711771
if len(p.Fields) == 0 {
17721772
return 0, ErrFieldsRequired
17731773
}
1774+
1775+
for _, f := range p.Fields {
1776+
if f == nil {
1777+
return 0, ErrFieldIsNull
1778+
}
1779+
}
17741780
}
17751781

17761782
// If the retention policy is not set, use the default for this database.

0 commit comments

Comments
 (0)