Skip to content

dolthub/dolt#9425 - Fix enum zero validation in strict mode#3076

Merged
elianddb merged 21 commits intomainfrom
elianddb/9425-enum-zero-strict-mode
Jul 10, 2025
Merged

dolthub/dolt#9425 - Fix enum zero validation in strict mode#3076
elianddb merged 21 commits intomainfrom
elianddb/9425-enum-zero-strict-mode

Conversation

@elianddb
Copy link
Copy Markdown
Contributor

@elianddb elianddb commented Jul 8, 2025

Fixes dolthub/dolt#9425:

  • Add strict mode check for 0 values in EnumType.Convert()
  • Return data truncation error for invalid 0 values in strict mode
  • Allow 0 values when empty string is explicitly defined as enum value
  • Add row number tracking in insertIter for accurate error reporting
  • Enhance enum errors with column name and row number
  • Fix ErrInvalidType formatting issues in enum expression

🤖 Generated with Claude Code

@elianddb elianddb force-pushed the elianddb/9425-enum-zero-strict-mode branch from 925b0e8 to 77b4675 Compare July 8, 2025 21:15
@elianddb elianddb force-pushed the elianddb/9425-enum-zero-strict-mode branch from 9fbc47b to 5ea6b1a Compare July 10, 2025 00:08
elianddb and others added 21 commits July 10, 2025 09:29
- Add strict mode check for 0 values in EnumType.Convert()
- Return data truncation error for invalid 0 values in strict mode
- Allow 0 values when empty string is explicitly defined as enum value
- Add row number tracking in insertIter for accurate error reporting
- Enhance enum errors with column name and row number
- Fix ErrInvalidType formatting issues in enum expression
- Add comprehensive test cases for strict/non-strict modes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
After MySQL comparison server testing, corrected logic to reject 0 values
in strict mode regardless of enum definition, matching MySQL behavior exactly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Modified columndefault.go to detect enum data truncation errors and return
ErrInvalidColumnDefaultValue instead of ErrIncompatibleDefaultType to match
MySQL behavior exactly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add early validation in tableSpecToSchema to catch enum default 0 before conversion
- Prevents columndefault.go from returning "(unknown)" in error messages
- Enhanced validateDefaultExprs to handle enum defaults with proper column context
- Now matches MySQL behavior exactly: "Invalid default value for 'column_name'"

Resolves the remaining column name issue for CREATE TABLE statements
while maintaining all existing INSERT validation functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use ctx.GetSessionVariable() instead of ctx.Session.GetSessionVariable()
to properly access session variables in the enum conversion context.
Allow uint16 enum indices to be converted without strict mode validation.
This fixes INSERT IGNORE behavior where stored uint16(0) values should
display as empty strings, matching MySQL behavior exactly.

Resolves the (unknown) error during SELECT after INSERT IGNORE.
Previously used fragile string matching to detect enum data truncation errors:
- if types.IsEnum(col.Type) && strings.Contains(cErr.Error(), "Data truncated for column")

Now enum Convert method returns ErrConvertingToEnum directly for invalid 0 values in strict mode,
which gets properly enhanced with column name and row number via existing error handling pattern:
- else if types.ErrConvertingToEnum.Is(cErr)

This eliminates the fragile string-parsing approach while maintaining exact same functionality
and MySQL-compatible error messages with proper column names and row numbers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused isInsertContext function from enum.go
- Fix import cycle by removing unnecessary types import from columndefault.go
- Restore necessary DDL validation for proper column name error reporting
- Maintain all functionality while eliminating fragile string matching patterns

All tests pass and MySQL comparison server behavior matches exactly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add comprehensive test case "enums with zero strict all tables"
- Tests single row insert, multi-row insert, and CREATE TABLE default scenarios
- Ensures both STRICT_TRANS_TABLES and STRICT_ALL_TABLES modes are covered
- Complements existing STRICT_TRANS_TABLES test for complete coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use SqlMode struct instead of manual string parsing in isStrictMode
- Leverage LoadSqlMode() and ModeEnabled() methods for proper SQL mode detection
- Unskip enum default validation tests that now work with our implementation
- Update expected error types to ErrInvalidColumnDefaultValue for enum defaults

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add validateEnumLiteralDefault method for stricter enum default validation
- Reject numeric index references ('1', 1) for literal enum defaults
- Allow only exact enum value matches for literal defaults
- Preserve original ErrInvalidType format in enum expression
- Fixes enums_with_default_values test failures

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Move validateEnumLiteralDefault to resolve_column_defaults.go
- Pass actual column name instead of '(unknown)' to match MySQL
- MySQL returns 'Invalid default value for 'column_name'' format
- Remove enum validation from CheckType to avoid duplicate logic
- Verified behavior matches MySQL exactly for both invalid cases

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@elianddb elianddb force-pushed the elianddb/9425-enum-zero-strict-mode branch from 5ea6b1a to 24ee22c Compare July 10, 2025 16:30
@elianddb elianddb requested a review from jycor July 10, 2025 17:30
Copy link
Copy Markdown
Contributor

@jycor jycor left a comment

Choose a reason for hiding this comment

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

LGTM

@elianddb elianddb merged commit 8b0896d into main Jul 10, 2025
8 checks passed
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.

0 value is not allowed for enum

2 participants