Skip to content

Fix ColumnDefinitionParser to parse unquoted DEFAULT NULL as SQL NULL - #1202

Open
Lugat wants to merge 2 commits into
yiisoft:masterfrom
Lugat:fix-default-null-definition
Open

Lugat wants to merge 2 commits into
yiisoft:masterfrom
Lugat:fix-default-null-definition

Conversation

@Lugat

@Lugat Lugat commented Oct 1, 2026

Copy link
Copy Markdown

As discussed in yiisoft/db-mysql#485: an unquoted NULL after DEFAULT was stored as defaultValueRaw = 'NULL'. The MySQL ColumnFactory typecasts it by column type, so int DEFAULT NULL was created as DEFAULT 0. This breaks the yiisoft/queue-db migration: messages are never reserved because reserved_at IS NULL never matches.

String defaults are always quoted in a column definition, so an unquoted NULL can only be SQL NULL. It is now parsed as defaultValueRaw = null. Schema reading from information_schema is not affected, so varchar DEFAULT 'NULL' keeps working.

Checked on MySQL 8.0: int DEFAULT NULL → DEFAULT NULL (was DEFAULT 0); int DEFAULT 5 and varchar(10) DEFAULT 'NULL' are unchanged.

Q A
Is bugfix? ✔️
New feature? ❌
Breaks BC? ❌
Fixed issues yiisoft/db-mysql#485

String defaults are always quoted in a column definition, so an unquoted
NULL can only be SQL NULL. Previously it was stored as defaultValueRaw
'NULL' and the MySQL column factory typecast it to 0 for integer columns
(e.g. 'int DEFAULT NULL' was created as DEFAULT 0).

See yiisoft/db-mysql#485
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (2d126ae) to head (f1ccc5f).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1202   +/-   ##
=========================================
  Coverage     98.63%   98.63%           
- Complexity     1653     1655    +2     
=========================================
  Files           123      123           
  Lines          4309     4311    +2     
=========================================
+ Hits           4250     4252    +2     
  Misses           59       59           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread CHANGELOG.md
Comment on lines +18 to +19
- Bug #1202: Fix `ColumnDefinitionParser` to parse an unquoted `DEFAULT NULL` as SQL `NULL` instead of the string
`'NULL'`, which MySQL typecast to `DEFAULT 0` for integer columns (@Lugat)

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.

Suggested change
- Bug #1202: Fix `ColumnDefinitionParser` to parse an unquoted `DEFAULT NULL` as SQL `NULL` instead of the string
`'NULL'`, which MySQL typecast to `DEFAULT 0` for integer columns (@Lugat)
- Bug #1202: Fix `ColumnDefinitionParser` to parse an unquoted `DEFAULT NULL` as SQL `NULL` instead of the string
`'NULL'` (@Lugat)

@vjik
vjik requested a review from a team October 1, 2026 09:22
@vjik vjik added the status:code review The pull request needs review. label Oct 1, 2026

@Tigrov Tigrov 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.

👍

$extra = $this->parseBoolValue($extra, '/\s*\bUNIQUE\b/i', 'unique', $info);
$extra = $this->parseBoolValue($extra, '/\s*\bNOT\s+NULL\b/i', 'notNull', $info);

// String defaults are always quoted in a column definition, so an unquoted `NULL` can only be SQL `NULL`

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.

Suggested change
// String defaults are always quoted in a column definition, so an unquoted `NULL` can only be SQL `NULL`

This comment looks redundant

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

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants