Skip to content

[16.0][FIX] pms: validate HH:MM hours with a single format check - #434

Merged
DarioLodeiros merged 1 commit into
OCA:16.0from
commitsun:16.0-fix-arrival-hour-format
Aug 24, 2026
Merged

[16.0][FIX] pms: validate HH:MM hours with a single format check#434
DarioLodeiros merged 1 commit into
OCA:16.0from
commitsun:16.0-fix-arrival-hour-format

Conversation

@jesusVMayor

Copy link
Copy Markdown
Member

Bug

The hour fields stored as Char (pms.property.default_arrival_hour and
default_departure_hour, pms.reservation.arrival_hour and departure_hour)
were checked with time.strptime(hour, "%H:%M"), which does not require zero
padding, so "8:00" passed the check and was stored.

The consumers read the hour by position, so int(arrival_hour[0:2]) is
int("8:"): a value the check accepted raised ValueError in
_compute_checkin_datetime, and everything reading checkin_datetime failed
with it, mail templates included.

Solution

One regex, ^([01]\d|2[0-3]):[0-5]\d$, replaces the four strptime calls, and
pms.property owns the only parser (is_valid_hour_str, hour_str_to_time
and datetime_from_hour_str), used both by the checks and by the checkin and
checkout datetime computes, which no longer slice the string.

Those computes return no value when the date or the hour is missing, instead of
raising TypeError, and the property hours become required: they always had a
default, and the empty branch only made the check raise.

Migration

The stricter check would leave the records holding an unpadded hour unwritable,
so 16.0.4.13.0/pre-migration.py normalizes what is already stored:

  • hours recoverable by zero padding are padded, "9:00" to "09:00"
  • "24:00" becomes "23:59", keeping its end of day meaning
  • empty property hours take the field default, now that they are required
  • anything else is left untouched and logged with its table, column and id:
    guessing a value would be worse than reporting it

@DarioLodeiros DarioLodeiros left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the migration in detail: the normalization is idempotent (already-valid values pass through the lpad unchanged), '24:00' is mapped to '23:59', empty property hours are filled before the fields become required, and whatever cannot be normalized is logged for manual review instead of being guessed. The single validation helper on pms.property plus the defensive computes remove the positional int(hour_str[0:2]) parsing that crashed cancellation mails.

Note for deployers: char hour values that the migration logs as not normalizable still need manual fixing — the computes will reject them at runtime.

The hour fields accepted anything time.strptime(hour, "%H:%M") parsed,
including hours without zero padding ("8:00") that the consumers, which
read the hour by position, could not parse back.

A single regex validates them now, pms.property owns the only parser,
and the checkin and checkout datetime computes use it instead of slicing
the string. The property hours become required, and a pre-migration
normalizes the values already stored.

Assisted-by: Claude Opus 5
@DarioLodeiros
DarioLodeiros force-pushed the 16.0-fix-arrival-hour-format branch from 7df89c1 to c2af07f Compare August 24, 2026 11:27
@DarioLodeiros
DarioLodeiros merged commit eb68983 into OCA:16.0 Aug 24, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants