Skip to content

fix: store the group expiration date as a datetime - #296

Open
italovalcy wants to merge 3 commits into
mainfrom
fix/group-expiration-date
Open

fix: store the group expiration date as a datetime#296
italovalcy wants to merge 3 commits into
mainfrom
fix/group-expiration-date

Conversation

@italovalcy

@italovalcy italovalcy commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #268

Problem

Setting an expiration date on a group always failed. The POST handler copied every form field straight onto the model, so the picker's raw string ("07/31/2026") landed on Groups.expiration, a db.DateTime column, and the driver rejected it at commit time:

TypeError: SQLite DateTime type only accepts Python datetime and date objects as input.

The user just saw the generic "Failed to update group." and lost the whole create/update, not only the date.

Fix

  • parse_group_expiration() in apps/utils.py converts the submitted YYYY-MM-DD string to a datetime; blank means "never expires"; anything else raises ValueError.
  • edit_group() runs the field through it and re-renders the form with "Invalid expiration date, please use the format YYYY-MM-DD." on a bad value, instead of blowing up in db.session.commit().
  • The picker used the locale-dependent moment format 'L' — the source of the 07/31/2026 in the report — and now uses YYYY-MM-DD. The stored value is rendered back with the same format so it round-trips through an edit; previously it rendered the full 2026-07-31 00:00:00 repr.
  • Drive-by: the expiration input's data-target still pointed at #reservationdate, an AdminLTE demo leftover with no matching element, now #expiredate.

Parsing is strict ISO on purpose. Also accepting MM/DD/YYYY would make 07/08/2026 ambiguous against the DD/MM/YYYY a pt_BR user types by hand, and a silently wrong date is worse than a visible error — the picker always fills ISO now.

Tests

parse_group_expiration unit tests plus two end-to-end cases: creating a group with expiration=2026-07-31 persists the datetime, and the old 07/31/2026 value is rejected without creating the group. Full suite: 617 passed.

pt_BR translation for the new message added to the master table; catalogs re-extracted and compiled.

Saving a group with an expiration date always failed: the form field was
copied verbatim onto Groups.expiration, a DateTime column, so the driver
rejected the raw string ("SQLite DateTime type only accepts Python
datetime and date objects as input") and the whole group create/update
was lost with a generic "Failed to update group." message.

Parse the field into a datetime before assigning it (new
parse_group_expiration() helper, empty means "never expires"), and
report a malformed date on the form instead of failing at commit time.

The date picker was configured with the locale-dependent moment format
'L', which is what produced the "07/31/2026" in the report; it now uses
YYYY-MM-DD, and the stored value is rendered back in the same format so
it round-trips through an edit (it previously rendered the full
"2026-07-31 00:00:00" repr). The date is parsed strictly as ISO: the
alternative, also accepting MM/DD/YYYY, cannot tell 07/08/2026 apart
from the DD/MM/YYYY a pt_BR user would type, so a wrong date would be
saved silently.

Also fixes the expiration input's data-target, left pointing at
"#reservationdate" (an AdminLTE demo leftover, no such element exists)
instead of the "#expiredate" group it belongs to.

Fixes #268

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@italovalcy
italovalcy marked this pull request as ready for review July 23, 2026 09:07
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 on expiration date for groups

1 participant