carlos / platform Public

console: registrant backfill skips unreadable purchase details

A malformed details row is logged and skipped by newestPurchaseContact,
so one bad row never stops migrateDomains or the console booting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c9a2cd74d56450277fd6e0e5fcc4c4272f85e021 parent 56d21a1
2 files changed, +49 −4
  • internal/console/domainstore.go +10 −4
  • internal/console/domainstore_test.go +39 −0
diff --git a/internal/console/domainstore.go b/internal/console/domainstore.go
index 7711cd25a..651fb2a98 100644
--- a/internal/console/domainstore.go
+++ b/internal/console/domainstore.go
@@ -7,6 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
+ "log"
"strings"
"time"
@@ -241,20 +242,25 @@ func (s *Store) backfillRegistrants(ctx context.Context) error {
return nil
}
+// newestPurchaseContact is the contact of the newest purchase for
+// accountID and domain whose details carry one. A row whose details do not
+// parse is logged and skipped: a data backfill never stops the console
+// booting.
func (s *Store) newestPurchaseContact(ctx context.Context, accountID int64, domain string) (registrar.Contact, error) {
- rows, err := s.db.QueryContext(ctx, `SELECT details FROM domain_purchases WHERE account_id = ? AND domain = ? ORDER BY created_at DESC, rowid DESC`, accountID, domain)
+ rows, err := s.db.QueryContext(ctx, `SELECT id, details FROM domain_purchases WHERE account_id = ? AND domain = ? ORDER BY created_at DESC, rowid DESC`, accountID, domain)
if err != nil {
return registrar.Contact{}, err
}
defer rows.Close()
for rows.Next() {
- var details string
- if err := rows.Scan(&details); err != nil {
+ var id, details string
+ if err := rows.Scan(&id, &details); err != nil {
return registrar.Contact{}, err
}
var d purchaseDetails
if err := json.Unmarshal([]byte(details), &d); err != nil {
- return registrar.Contact{}, err
+ log.Printf("console: registrant backfill of %s: purchase %s has unreadable details, skipped: %v", domain, id, err)
+ continue
}
if d.Contact != (registrar.Contact{}) {
return d.Contact, nil
diff --git a/internal/console/domainstore_test.go b/internal/console/domainstore_test.go
index 429ac09dd..bb503a36e 100644
--- a/internal/console/domainstore_test.go
+++ b/internal/console/domainstore_test.go
@@ -529,6 +529,45 @@ func TestMigratedContactRemovalSurvivesReopen(t *testing.T) {
}
}
+// TestBackfillSkipsMalformedPurchaseDetails: a purchase whose details do
+// not parse is logged and skipped by the registrant backfill; the store
+// still opens, and the other registrations are backfilled (the next
+// readable purchase of the same domain, if any, supplies the contact).
+func TestBackfillSkipsMalformedPurchaseDetails(t *testing.T) {
+ ctx := t.Context()
+ path := filepath.Join(t.TempDir(), "console.db")
+ s, err := Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ registered, done := seedLegacyDomainState(t, s)
+ // two.example's newest purchase, and three.example's only one, are
+ // malformed.
+ if _, err := s.db.Exec(`UPDATE domain_purchases SET details = '{not json' WHERE id = 'dp_0000000000000004'`); err != nil {
+ t.Fatal(err)
+ }
+ if err := s.CreateDomainPurchase(DomainPurchase{ID: "dp_0000000000000006", AccountID: 123, Domain: "three.example", State: PurchaseFailed,
+ CreatedAt: time.Date(2026, 11, 2, 0, 0, 0, 0, time.UTC)}); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.db.Exec(`UPDATE domain_purchases SET details = '[' WHERE id = 'dp_0000000000000006'`); err != nil {
+ t.Fatal(err)
+ }
+ if err := s.Close(); err != nil {
+ t.Fatal(err)
+ }
+ if s, err = Open(path); err != nil {
+ t.Fatalf("a malformed purchase row stopped the store opening: %v", err)
+ }
+ t.Cleanup(func() { s.Close() })
+ for domain, want := range map[string]registrar.Contact{"one.example": registered, "two.example": done, "three.example": {}} {
+ r, err := s.DomainRegistrationFor(ctx, 123, domain)
+ if err != nil || r == nil || r.Registrant != want {
+ t.Fatalf("%s registrant: %+v, %v; want %+v", domain, r, err, want)
+ }
+ }
+}
+
func TestDomainObligations(t *testing.T) {
ctx := t.Context()
s := openTestStore(t)