dolthub/dolt#9425 - Fix enum zero validation in strict mode#3076
Merged
dolthub/dolt#9425 - Fix enum zero validation in strict mode#3076
Conversation
925b0e8 to
77b4675
Compare
jycor
reviewed
Jul 9, 2025
jycor
reviewed
Jul 9, 2025
9fbc47b to
5ea6b1a
Compare
- 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>
5ea6b1a to
24ee22c
Compare
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 dolthub/dolt#9425:
🤖 Generated with Claude Code