fix: store the group expiration date as a datetime - #296
Open
italovalcy wants to merge 3 commits into
Open
Conversation
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
marked this pull request as ready for review
July 23, 2026 09:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onGroups.expiration, adb.DateTimecolumn, and the driver rejected it at commit time:The user just saw the generic "Failed to update group." and lost the whole create/update, not only the date.
Fix
parse_group_expiration()inapps/utils.pyconverts the submittedYYYY-MM-DDstring to adatetime; blank means "never expires"; anything else raisesValueError.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 indb.session.commit().'L'— the source of the07/31/2026in the report — and now usesYYYY-MM-DD. The stored value is rendered back with the same format so it round-trips through an edit; previously it rendered the full2026-07-31 00:00:00repr.data-targetstill pointed at#reservationdate, an AdminLTE demo leftover with no matching element, now#expiredate.Parsing is strict ISO on purpose. Also accepting
MM/DD/YYYYwould make07/08/2026ambiguous against theDD/MM/YYYYa 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_expirationunit tests plus two end-to-end cases: creating a group withexpiration=2026-07-31persists the datetime, and the old07/31/2026value 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.