Skip to content

Fix: validate Hebrew date day against month length#228

Open
abeperl wants to merge 2 commits intoabe-101:mainfrom
abeperl:fix/issue-28-validate-hebrew-date
Open

Fix: validate Hebrew date day against month length#228
abeperl wants to merge 2 commits intoabe-101:mainfrom
abeperl:fix/issue-28-validate-hebrew-date

Conversation

@abeperl
Copy link
Copy Markdown

@abeperl abeperl commented Mar 6, 2026

Summary

  • Adds form-level validation to HebrewDateForm that rejects day values exceeding the month's actual length (e.g., day 30 for Iyar which only has 29 days)
  • Uses the existing lengths_of_months lookup from hebrew_date.py for the validation check
  • Returns a clear error message with the month name and valid day range
  • Adds 3 test cases covering invalid day, valid boundary day, and valid 30-day month

Problem

The UI allows selecting any day (1–30) for any Hebrew month, but some months only have 29 days. Submitting day 30 for a 29-day month (Iyar, Tammuz, Elul, Tevet, Adar B) causes an unhandled 500 error.

Test plan

  • Select Iyar + day 30 → form shows validation error instead of 500
  • Select Nisan + day 30 → form submits successfully
  • Select Iyar + day 29 → form submits successfully
  • Run pytest my_hebrew_dates/hebcal/tests/test_forms.py → all tests pass

Closes #28

🤖 Generated with Claude Code

Some Hebrew months only have 29 days (e.g. Iyar, Tammuz, Elul, Tevet,
Adar B), but the form allowed selecting day 30 for any month, causing
a 500 error on submission. This adds form-level validation that checks
the selected day does not exceed the month's actual length.

Fixes abe-101#28

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@abe-101 abe-101 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!
Overall the change looks good.
Left one small nitpick comment which isn't a blocker.
Please fix CI and I'll happily merge it :)

data={"name": "Test Date", "month": 2, "day": 30, "event_type": "🎂"},
)
assert not form.is_valid()
assert "__all__" in form.errors
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we narrow this assert to be more specific. Like perhaps it should assert the d of the error message

- Assign f-string to variable before raise (fixes EM102, TRY003)
- Replace en dash with hyphen (fixes RUF001)
- Assert error message content in day validation test
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: The UI allows setting an illegal date, e.g. 30 iyar, which then throws a 500 when submitting

3 participants