Skip to content

KAN-321 Fix NULL-only text failures in UAT provisioning - #505

Merged
corrin merged 4 commits into
mainfrom
KAN-321-null-only-text-migration-production-data
Jul 31, 2026
Merged

KAN-321 Fix NULL-only text failures in UAT provisioning#505
corrin merged 4 commits into
mainfrom
KAN-321-null-only-text-migration-production-data

Conversation

@corrin

@corrin corrin commented Jul 31, 2026

Copy link
Copy Markdown
Owner

What changed

  • Render unset optional phone-provider credentials as JSON null in instance.sh, rather than an empty string.
  • Normalize empty optional Xero account fields to None in both regular account sync and seed_xero_from_database.
  • Add database-backed regressions for the rendered phone fixture, the demo Xero account seed (including account 805, Accrued Liabilities), and regular account sync.
  • Tighten the touched ingestion function annotations and remove three resolved mypy-baseline entries.

Root cause

The new database checks make NULL the only valid representation of unset nullable text, but two provisioning writers bypassing serializers still emitted empty strings:

  1. instance.sh reconfigure quoted absent phone credentials in its JSON fixture.
  2. Xero account ingestion copied optional SDK strings verbatim, including the empty description on account 805.

Impact

A scrubbed UAT restore can now be reconfigured with a disabled/unconfigured phone provider, and demo Xero seeding can ingest accounts whose optional fields are empty. Configured non-empty values are unchanged.

Validation

  • Focused Django tests passed for phone fixture rendering/loading and both Xero account ingestion paths.
  • bash -n scripts/server/instance.sh
  • Strict mypy gate passed with no new errors; three baseline entries were removed.
  • Commit and push gates passed, including shellcheck, backend lint/schema checks, 409 frontend unit tests, ESLint, Vue type-check, typed-router check, production build, and workflow formatting.

Jira: https://docketworks.atlassian.net/browse/KAN-321

Summary by CodeRabbit

  • Bug Fixes

    • Removed unsupported “Last Login” data from staff APIs, forms, tables, and search.
    • Staff creation now ignores supplied login timestamp values.
    • Empty Xero account fields are stored as null, including when clearing existing descriptions.
    • Phone provider fixtures now load safely when optional settings are missing.
  • Tests

    • Added regression coverage for staff data, Xero account synchronization, and unconfigured phone provider settings.

corrin and others added 3 commits July 31, 2026 15:57
Nothing in DocketWorks ever writes Staff.last_login. Authentication is
JWT-only: SIMPLE_JWT leaves UPDATE_LAST_LOGIN at its False default, and
CustomTokenObtainPairSerializer authenticates via authenticate(), which
never emits the user_logged_in signal that Django's update_last_login
receiver listens for. django.contrib.admin is not installed either, so
there is no session-login path. The inherited AbstractBaseUser column
has been NULL by construction.

Admin > Staff nonetheless rendered a permanently blank "Last Login"
column, and StaffFormModal round-tripped the value back to the server
with no input bound to it. Worse, StaffCreateSerializer listed only
wage_rate as read-only, so POST /api/accounts/staff/ accepted a
client-supplied last_login -- an API client could forge a login time.

Remove last_login from STAFF_API_FIELDS and from the admin staff table
(fixing the empty-state colspan, which was already off by one), and drop
the dead last_login/date_joined round-trip from StaffFormModal. The DB
column stays; it belongs to AbstractBaseUser.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CvGn5ojk7NtQzr5WmzAEi
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@corrin, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e23d4597-0f62-40f0-b13b-4adfc86fdced

📥 Commits

Reviewing files that changed from the base of the PR and between 445afbf and ac5e031.

📒 Files selected for processing (2)
  • apps/workflow/api/xero/transforms.py
  • apps/workflow/management/commands/seed_xero_from_database.py
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch KAN-321-null-only-text-migration-production-data

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@corrin
corrin marked this pull request as ready for review July 31, 2026 19:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/workflow/api/xero/transforms.py`:
- Line 1012: Remove the missing-attribute fallback in the account description
mappings: use the required description attribute directly in
apps/workflow/api/xero/transforms.py lines 1012-1012 and
apps/workflow/management/commands/seed_xero_from_database.py lines 214-214,
replacing getattr(account, "description", None) with direct account.description
access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a0ca138b-5c74-4546-91ec-c993001ed0d7

📥 Commits

Reviewing files that changed from the base of the PR and between 03a4ef9 and 445afbf.

⛔ Files ignored due to path filters (1)
  • frontend/src/api/generated/api.ts is excluded by !**/generated/**
📒 Files selected for processing (13)
  • apps/accounts/models.py
  • apps/accounts/serializers.py
  • apps/accounts/tests/test_staff_api.py
  • apps/workflow/api/xero/transforms.py
  • apps/workflow/management/commands/seed_xero_from_database.py
  • apps/workflow/tests/test_seed_xero_from_database.py
  • apps/workflow/tests/test_xero_instance_templates.py
  • frontend/schema.yml
  • frontend/src/components/StaffFormModal.vue
  • frontend/src/views/AdminStaffView.vue
  • mypy-baseline.txt
  • scripts/server/instance.sh
  • scripts/server/templates/phone-provider-settings.json.template
💤 Files with no reviewable changes (4)
  • apps/accounts/serializers.py
  • frontend/src/components/StaffFormModal.vue
  • frontend/schema.yml
  • mypy-baseline.txt

Comment thread apps/workflow/api/xero/transforms.py Outdated
`getattr(account, "description", None)` and
`getattr(account, "enable_payments_to_account", False)` both imply the
attribute might be absent. Neither ever is: both are declared in
`Account.openapi_types` and initialised in the xero-python constructor,
so the defaults are unreachable. Verified against all 166 XeroAccount
rows — both keys present in every raw payload, and
`enable_payments_to_account` is never null (148 False / 18 True).

Pure dead-code removal, no behaviour change. The sibling fields in the
same dict already use direct access (`account.type or None`), so this
also removes an internal inconsistency.

`or None` is retained on `description` — 57 of 166 accounts come back
from Xero with `""`, and that clause is what turns them into NULL. It is
deliberately not added to `enable_payments`: coercing a null to False
would mask a genuinely surprising value, where the NOT NULL constraint
fails early instead.

Raised by CodeRabbit on PR #505.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016TZsTtMB6opqWJFwzrUteK
@corrin
corrin merged commit 2594e93 into main Jul 31, 2026
9 checks passed
@corrin
corrin deleted the KAN-321-null-only-text-migration-production-data branch July 31, 2026 20:39
@corrin corrin mentioned this pull request Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant