Skip to content

[Compatibility]: ALLOW_INVALID_DATES is accepted but DATE and DATETIME remain strictly validated #28602

Open

Description

@Ariznawlll

Environment

  • MatrixOne: main at fc621e3616d229c7a29d0c80e73ed8eb1997459c
  • MySQL reference: 8.0.46
  • Session time zone: +00:00

Problem

MatrixOne accepts ALLOW_INVALID_DATES in sql_mode, but still rejects calendar-invalid DATE and DATETIME values such as 2024-02-30. The mode does not change direct writes, updates, prepared parameters, or column defaults.

MySQL documents that ALLOW_INVALID_DATES permits month values 1-12 and day values 1-31 without checking the day against the actual number of days in the month. It applies to DATE and DATETIME, not TIMESTAMP.

Minimal reproduction

SET SESSION sql_mode = 'STRICT_TRANS_TABLES,ALLOW_INVALID_DATES';

CREATE TABLE t(
  id INT PRIMARY KEY,
  d DATE,
  dt DATETIME(6)
);

INSERT INTO t VALUES(
  1,
  '2024-02-30',
  '2024-02-30 12:34:56.123456'
);

SELECT id, CAST(d AS CHAR), CAST(dt AS CHAR) FROM t;

MatrixOne returns:

ERROR 20203: invalid argument parsedate, bad value 2024-02-30

MySQL 8.0.46 stores and returns:

1 | 2024-02-30 | 2024-02-30 12:34:56.123456

Without ALLOW_INVALID_DATES, both systems reject the same row.

Covered boundaries and paths

The behavior was checked with 2024-02-30, non-leap 2023-02-29, and 2024-04-31.

  • Direct INSERT, UPDATE, and SQL PREPARE ... EXECUTE ... USING parameters are accepted by MySQL under the mode and rejected by MatrixOne.
  • MySQL accepts DATE DEFAULT '2024-02-30' and DATETIME DEFAULT '2024-02-30 12:34:56' under the mode; MatrixOne rejects the table definition.
  • MySQL can subsequently evaluate YEAR, MONTH, DAY, DAYOFMONTH, LAST_DAY, DATE_ADD, and DATEDIFF over the stored value. MatrixOne has no equivalent stored-value path because every entry point rejects it.
  • 2024-13-01 and 2024-01-32 are rejected by both systems even with the mode, confirming that the expected range is not arbitrary invalid input.
  • A row containing an invalid TIMESTAMP is rejected by both systems, confirming MySQL's documented exclusion of TIMESTAMP from this mode.

Code analysis

pkg/frontend/variables.go lists ALLOW_INVALID_DATES as a valid sql_mode token, but there are no consumers of this token outside that registration. types.ParseDate and types.ParseDatetime always validate the calendar date and do not receive session SQL mode information. DML binding, prepared execution, and default-value validation therefore cannot select the relaxed rule.

The behavior above was reproduced three times with fresh databases and connections. Each relaxed-mode case has a strict-mode control, and the out-of-range month/day plus TIMESTAMP controls prevent widening the expected behavior beyond MySQL's documented scope.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. XuPeng-SH commented on Sep 10, 2026

    @XuPeng-SH
    Contributor

    Triage routing: assigned to @jiangxinmeng1. Labels normalized to kind/bug + needs-triage (existing compatibility labels, when present, are retained).

    Recommended PR decomposition:

    • PR-T9 — invalid-date mode (#28602 only): define ALLOW_INVALID_DATES behavior for DATE/DATETIME parsing and validation. Keep it separate from DST gap handling (#28570) because invalid calendar dates and nonexistent local times are different contracts.

    Suggested priority: P2; cover zero dates, invalid month/day values, strict/non-strict modes, and round-trip behavior.

  4. XuPeng-SH commented on Sep 27, 2026

    @XuPeng-SH
    Contributor

    Decision for #29076 (2026-09-27): defer full ALLOW_INVALID_DATES support from this PR. The mode token remains accepted for connection compatibility, but DATE/DATETIME still reject impossible calendar dates; this issue remains open and must not be marked fixed by #29076.

    Reason: correct support requires preserving the civil fields through scalar storage, tuple/index ordering, WAL/logtail, backup/restore, and calendar functions. The earlier #29076 draft changed valid persisted tuple keys and had unresolved recovery/upgrade safety gaps; that implementation has now been removed from the PR. The compatibility requirement for a future design is that all previously stored valid DATE/DATETIME values and index keys remain readable without a rewrite after an offline upgrade. Once new invalid-date values have been written, direct downgrade to an old reader need not be supported.

    Revisit when there is a concrete workload that must store such dates, with an approved storage/restore design and old-data upgrade plus index/SQL regression evidence. Existing applications that merely set the MySQL mode are not forced to change their initialization now.

  5. fengttt commented on Sep 29, 2026

    @fengttt
    Contributor

    What are we doing? Why we would accept this flag and put in bad values? What is the point of introduce bugs to the database?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitydeferredkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions