Skip to content

Commit 91d2c0f

Browse files
Properly handle nil notification
1 parent 145c366 commit 91d2c0f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

driver/sql/postgres/projector_stream_storage.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ func (s *streamProjectionStorage) PersistState(conn driverSQL.Execer, notificati
108108
return err
109109
}
110110
s.logger.Debug("updated projection state", func(e goengine.LoggerEntry) {
111-
e.Int64("notification.no", notification.No)
112-
e.String("notification.aggregate_id", notification.AggregateID)
111+
if notification == nil {
112+
e.Any("notification", nil)
113+
} else {
114+
e.Int64("notification.no", notification.No)
115+
e.String("notification.aggregate_id", notification.AggregateID)
116+
}
113117
e.Any("state", state)
114118
})
115119

@@ -121,16 +125,21 @@ func (s *streamProjectionStorage) Acquire(
121125
conn *sql.Conn,
122126
notification *driverSQL.ProjectionNotification,
123127
) (func(), *driverSQL.ProjectionRawState, error) {
124-
logFields := func(e goengine.LoggerEntry) {
125-
e.Int64("notification.no", notification.No)
126-
e.String("notification.aggregate_id", notification.AggregateID)
127-
}
128-
129-
var res *sql.Row
128+
var (
129+
res *sql.Row
130+
logFields func(e goengine.LoggerEntry)
131+
)
130132
if notification == nil {
131133
res = conn.QueryRowContext(ctx, s.queryAcquireLock, s.projectionName)
134+
logFields = func(e goengine.LoggerEntry) {
135+
e.Any("notification", nil)
136+
}
132137
} else {
133138
res = conn.QueryRowContext(ctx, s.queryAcquirePositionLock, s.projectionName, notification.No)
139+
logFields = func(e goengine.LoggerEntry) {
140+
e.Int64("notification.no", notification.No)
141+
e.String("notification.aggregate_id", notification.AggregateID)
142+
}
134143
}
135144

136145
var (

0 commit comments

Comments
 (0)