Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions runtime/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ func (s *Server) GetModelPartitions(ctx context.Context, req *runtimev1.GetModel
defer release()

defaultPageSize := 100
pageLimit := pagination.ValidPageSize(req.PageSize, defaultPageSize)
opts := &drivers.FindModelPartitionsOptions{
ModelID: partitionsModelID,
WherePending: req.Pending,
WhereErrored: req.Errored,
BeforeExecutedOn: beforeExecutedOn,
AfterKey: afterKey,
Limit: pagination.ValidPageSize(req.PageSize, defaultPageSize),
Limit: pageLimit,
}

partitions, err := catalog.FindModelPartitions(ctx, opts)
Expand All @@ -342,9 +343,9 @@ func (s *Server) GetModelPartitions(ctx context.Context, req *runtimev1.GetModel
}

var nextPageToken string
if len(partitions) == pagination.ValidPageSize(req.PageSize, defaultPageSize) {
if len(partitions) == pageLimit && len(partitions) > 0 {
last := partitions[len(partitions)-1]
nextPageToken = pagination.MarshalPageToken(last.Index, last.Key)
nextPageToken = modelPartitionPageToken(last)
}

return &runtimev1.GetModelPartitionsResponse{
Expand All @@ -353,6 +354,14 @@ func (s *Server) GetModelPartitions(ctx context.Context, req *runtimev1.GetModel
}, nil
}

func modelPartitionPageToken(partition drivers.ModelPartition) string {
var executedOn time.Time
if partition.ExecutedOn != nil {
executedOn = *partition.ExecutedOn
}
return pagination.MarshalPageToken(executedOn, partition.Key)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Pagination fails for pending partitions with NULL ExecutedOn

When paginating through pending partitions (where ExecutedOn is NULL), modelPartitionPageToken encodes a zero time. On the next page request, this zero time is passed as BeforeExecutedOn, causing the SQL query to include both executed_on IS NULL (from WherePending) and comparison conditions like executed_on < zero_time. Since SQL NULL values don't compare equal to or less than any actual value, these conditions are mutually exclusive and the query returns zero results. The pagination effectively breaks on the second page for pending partitions.

Fix in Cursor Fix in Web


// CreateTrigger implements runtimev1.RuntimeServiceServer
func (s *Server) CreateTrigger(ctx context.Context, req *runtimev1.CreateTriggerRequest) (*runtimev1.CreateTriggerResponse, error) {
s.addInstanceRequestAttributes(ctx, req.InstanceId)
Expand Down
44 changes: 44 additions & 0 deletions runtime/server/controller_pagination_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package server

import (
"testing"
"time"

"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/pagination"
"github.com/stretchr/testify/require"
)

func TestModelPartitionPageToken_ExecutedOn(t *testing.T) {
ts := time.Date(2024, time.March, 5, 12, 0, 0, 0, time.UTC)
partition := drivers.ModelPartition{
Key: "abc123",
ExecutedOn: &ts,
}

token := modelPartitionPageToken(partition)
require.NotEmpty(t, token)

var decoded time.Time
var decodedKey string
err := pagination.UnmarshalPageToken(token, &decoded, &decodedKey)
require.NoError(t, err)
require.True(t, ts.Equal(decoded))
require.Equal(t, partition.Key, decodedKey)
}

func TestModelPartitionPageToken_NilExecutedOn(t *testing.T) {
partition := drivers.ModelPartition{
Key: "pending",
}

token := modelPartitionPageToken(partition)
require.NotEmpty(t, token)

var decoded time.Time
var decodedKey string
err := pagination.UnmarshalPageToken(token, &decoded, &decodedKey)
require.NoError(t, err)
require.True(t, decoded.IsZero())
require.Equal(t, partition.Key, decodedKey)
}
Loading