Skip to content

fix: validate datatype integer bounds in core type registry (#1170) - #1171

Closed
zerafachris wants to merge 1 commit into
ClickHouse:mainfrom
zerafachris:fix/datetime64-integer-bounds-1170
Closed

zerafachris wants to merge 1 commit into
ClickHouse:mainfrom
zerafachris:fix/datetime64-integer-bounds-1170

Conversation

@zerafachris

Copy link
Copy Markdown
Contributor

Fixes #1170

Root Cause

ClickHouseType.build() and Decimal.build() constructed datatype instances without checking cls._type_args.integer_bounds or argument counts. As a result, get_from_name() accepted out-of-range or malformed arguments such as DateTime64(10) or DateTime64(-1), producing broken type instances (for example nano_divisor == 0 and integer overflow during inserts) instead of failing at parse time.

Changes

  • Add ClickHouseType._validate_type_def() to check argument counts and positional _TypeArgs.integer_bounds before building datatype instances.
  • Call _validate_type_def() in ClickHouseType.build() and Decimal.build() (plus scale <= prec).
  • Add unit tests in tests/unit_tests/test_chtypes.py covering out-of-range and malformed arguments for DateTime64, Time64, FixedString, and Decimal*.

Verification

  • pytest -o addopts="" tests/unit_tests/test_chtypes.py tests/unit_tests/test_driver/test_parser.py tests/unit_tests/test_binary_value.py tests/unit_tests/test_dynamic.py (342 passed)

Prepared with AI assistance (OpenCode), reviewed for correctness before submission.

@zerafachris
zerafachris force-pushed the fix/datetime64-integer-bounds-1170 branch 2 times, most recently from 09a712d to 39c54f7 Compare November 10, 2026 04:50
@zerafachris
zerafachris force-pushed the fix/datetime64-integer-bounds-1170 branch from 39c54f7 to 1fa3132 Compare November 10, 2026 04:50
@joe-clickhouse

Copy link
Copy Markdown
Contributor

Thank you for this but I are closing it along with along with the #1170 issue. The reasons are listed there. The review also found these problems:

  • SQLAlchemy FixedString() and numpy integer arguments now fail.
  • Some inputs now raise ValueError, which is outside ClickHouseError.
  • mypy and ruff format fail.

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.

Type registry accepts out-of-range DateTime64 precision (e.g. DateTime64(10), DateTime64(-1)) instead of raising

2 participants