Skip to content

Reject null name, profession and role when updating a profile - #756

Open
1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:755-reject-null-profile-fields
Open

1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:755-reject-null-profile-fields

Conversation

@1sakshm

@1sakshm 1sakshm commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Description

PATCH /api/v1/profiles/{profile_id} returned 500 when the body set name, profession or role to null. ProfileUpdate declares them str | None = None so they can be left out, but an explicit null also passed validation, was copied onto the row, and the commit failed on the NOT NULL constraint (sqlite3.IntegrityError: NOT NULL constraint failed: profiles.name).

This adds a field_validator on ProfileUpdate that rejects None for those three fields, so the request now gets the usual 422 VALIDATION_ERROR naming the field, and the profile is left unchanged.

PATCH body Before After
{"name": null} (or profession / role) 500, IntegrityError 422 VALIDATION_ERROR, field name
{"role": "Battalion Chief"} 200 200 (unchanged)
{"description": null, "custom_fields": null} 200 200 (unchanged; both columns are nullable)

Omitted fields aren't validated, so partial updates work as before. The Settings page always sends strings, so no frontend change is needed.

Fixes #755

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added to tests/test_v1_profiles.py:
    • test_profile_patch_rejects_null_required_field (name, profession, role): 422 naming the field, and a follow-up GET shows the value unchanged. All three fail on development with the IntegrityError above.
    • test_profile_patch_allows_null_optional_fields: description / custom_fields can still be cleared, other fields untouched.
  • Full suite: python -m pytest tests/ → 417 passed
  • ruff check app/ → all checks passed

Test Configuration:

  • Python version: 3.11
  • Docker/Compose version: N/A (tests run locally)
  • OS: Windows 11

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • The Lint workflow check passes on this PR ✅
  • The Tests workflow check passes on this PR ✅

These columns are NOT NULL, so an explicit null in PATCH
/profiles/{id} failed on commit with a 500. It is now a 422
VALIDATION_ERROR and the profile is left unchanged.

Fixes fireform-core#755

This branch has not been deployed

No deployments
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.

[BUG]: PATCH /profiles/{id} returns 500 when name, profession or role is null

1 participant