Summary
Exports failed with the error:
NoMethodError: undefined method `contract_effective_date' for nil:NilClass
Root cause was a missing current_version_id (or a current_version_id that pointed to no row) on one or more subscriptions, leading application code to call a field on a nil subscription_version.
Fix was to identify affected subscriptions and backfill the correct subscription_versions.id into subscriptions.current_version_id.
Symptoms
Subscription export job fails.
Grafana shows
NoMethodError: undefined method 'contract_effective_date'.Related customer case open in Zendesk.


References
Grafana (auth required): https://infra-monitoring-us-sandbox.ordwaylabs.com/d/BBR-K93Mk/ordway-defaultworker-logs?orgId=1&from=1756218620000&to=1756221619000&var-search=129341408
Zendesk Ticket:
https://ordwaylabs.zendesk.com/agent/tickets/19107Ops/Jira Work Item (example):
OPS-5875
Root Cause
The exporter expects subscription.current_version to exist and exposes attributes such as contract_effective_date. When subscriptions.current_version_id is NULL or references a non-existent row in subscription_versions, current_version resolves to nil, causing the NoMethodError.
How to Diagnose
Confirm the error in Grafana
Filter for the export job logs and locate the stack trace mentioning
contract_effective_date.
Find impacted subscriptions (company-specific)
SELECT s.*, sv.id AS "version id" FROM subscriptions s LEFT JOIN subscription_versions sv ON s.current_version_id = sv.id WHERE s.company_id = 1167 AND sv.id IS NULL;Returns subscriptions whose
current_version_idis missing or invalid.
(Optional) Find impacted subscriptions across all companies
SELECT s.id AS subscription_id, s.company_id, s.current_version_id FROM subscriptions s LEFT JOIN subscription_versions sv ON s.current_version_id = sv.id WHERE sv.id IS NULL;Identify the correct version to backfill
The “current” version is typically the latest active
subscription_versionsrecord for that subscription.
-- Replace :subscription_id with the ID you’re fixing SELECT id FROM subscription_versions WHERE subscription_id = :subscription_id ORDER BY created_at DESC LIMIT 1;
Resolution
One-off backfill (example from OPS-5875)
Update the subscriptions.current_version_id with the correct subscription_versions.id.
UPDATE public.subscriptions
SET current_version_id = 2312036
WHERE id = 1047314;
Important: Always capture the previous value for rollback and record the change in the work item (e.g.,
OPS-5875).
Validate the fix
Re-run diagnosis query — the row should no longer appear in the “missing version” list.
Re-run the export job (or trigger the failing path) and confirm success in Grafana.
Functional spot-check: Pick one corrected subscription and confirm the expected effective date and export payload.
Comments
0 comments
Please sign in to leave a comment.