Skip to content

Fix 500 error when creating contestant without birth_date - #180

Merged
heming-h merged 2 commits into
mainfrom
copilot/fix-contestant-creation-bug
Apr 29, 2026
Merged

Fix 500 error when creating contestant without birth_date#180
heming-h merged 2 commits into
mainfrom
copilot/fix-contestant-creation-bug

Conversation

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Contestant.serialize_birth_date unconditionally called .isoformat() on the value, crashing with AttributeError: 'NoneType' object has no attribute 'isoformat' when the optional birth_date field was omitted.

Changes

  • app/models/contestant_model.py: Update serialize_birth_date to accept date | None and return None when no date is provided — consistent with how serialize_email already handles its optional field:
# Before
@field_serializer("birth_date")
def serialize_birth_date(self, dt: date) -> str:
    return dt.isoformat()

# After
@field_serializer("birth_date")
def serialize_birth_date(self, dt: date | None) -> str | None:
    return dt.isoformat() if dt else None
  • tests/integration/test_contestants.py: Add test_create_contestant_without_birth_date covering the POST /events/{id}/contestants path with birth_date=None.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv /home/REDACTED/.local/bin/uv run pytest tests/integration/test_contestants.py::test_create_contestant_without_birth_date tests/integration/test_contestants.py::test_create_contestant_good_case -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 29, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix bug when creating contestant without birth date Fix 500 error when creating contestant without birth_date Apr 29, 2026
Copilot AI requested a review from heming-h April 29, 2026 20:30
@heming-h
heming-h marked this pull request as ready for review April 29, 2026 20:40
@heming-h
heming-h merged commit 344ad0d into main Apr 29, 2026
3 checks passed
@heming-h
heming-h deleted the copilot/fix-contestant-creation-bug branch April 29, 2026 20:43
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 when creating contestant without birth_date

2 participants