Repository navigation
describe() reads an enum whose values contain a colon correctly - #1730
Merged
Merged
Conversation
The declared type at the start of a column comment ended at the first
colon, so enum('10:00','11:00') was cut inside its first value. The type
now ends at the first colon outside a quoted string, and still cannot
span lines.
Fixes #1724
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
November 21, 2026 01:21
alter() read the :type: marker of a declared comment up to the first
colon, so with enum('10:00','11:00') it ended inside a value and the
{old_name} rename marker after it went unnoticed. The attribute was then
dropped and added again empty. The marker is now split off with
split_type_comment, the same quote-aware reader the heading uses.
This was referenced Nov 21, 2026
MilagrosMarin
previously approved these changes
Nov 28, 2026
MilagrosMarin
left a comment
Contributor
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, this is a clean fix with tests that actually guard it.
- Ran the new tests on MySQL and PostgreSQL after merging current master: 16 integration and 40 unit tests pass. The full suite passes too (2105 passed, 17 skipped).
- Put back master's
heading.pyanddeclare.py: 10 of the 16 integration tests fail. With only thedeclare.pychange removed, all 4test_rename_enum_with_colon_keeps_valuescases fail, as the description says. - Checked the parser against a doubled quote (
'a''b:c'), a double-quoted value, an empty comment after the type, a missing closing colon, and{start}after the enum type. All are read correctly. - Merge order: this conflicts with #1639 in
declare.pyandtest_alter_rename.pywhichever merges second. I tried #1721, then #1639, then this PR. Keeping #1639's_make_attribute_alterand makingtest_rename_enum_with_colon_keeps_valuesexpect the values to be kept on both backends was enough, and the full suite passed (2213 passed, 18 skipped). - Minor: a value with a backslash-escaped quote and a colon, such as
'it\'s:x', is still read as a plain comment. That predates this PR and may not be worth handling. - Nit: the docstring of
test_rename_enum_with_colon_keeps_valuestells the story of the bug. One line naming the rule under test would be enough.
With #1721 in first, this makes describe() and alter() safe for time-of-day enums like '10:00'.
MilagrosMarin
approved these changes
Dec 1, 2026
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.
Summary
DataJoint records an attribute's declared type at the start of the column comment as
:type:comment. For an enum whose values contain a colon, such asenum('10:00','11:00'), the type was read only up to the first colon. Sooriginal_typebecameenum('10, the comment began with00','11:00'), anddescribe()printed a definition that could not be declared again.The type now ends at the first colon outside a quoted string. The enum is read whole, the comment is read correctly, and
describe()round-trips on both backends.alter()reads the type marker in front of a{old_name}rename marker the same way, so it also finds a rename on such an attribute.Fixes #1724
Merge order
split_type_comment. Merge 1721 first. Until then, this PR's diff also shows the 1721 commits; this PR's own changes are the last two commits._make_attribute_alterand removesoriginal_regexp. It reads the rename marker from the comment before the:type:marker is added, so the parser change indeclare.pyhere is not needed once 1639 is in. Whichever of 1639 and this PR merges second must reconcile the two: keep 1639's_make_attribute_alter, keeptest_rename_enum_with_colon_keeps_values, and change that test's PostgreSQL branch to expect the rename to keep the values, as 1639 does fortest_rename_keeps_values.Changes
heading.py: the pattern that reads the type from a column comment treats single- and double-quoted strings as part of the type, so a colon inside quotes does not end it. The type still cannot span lines, inside quotes too. A marker that is not a known core or codec type is still read as a plain comment, as in 1721.declare.py:_make_attribute_altersplits the:type:marker off the declared comment withsplit_type_commentbefore it looks for the{old_name}rename marker. It used to read the marker up to the first colon, so afterenum('10:00','11:00')it missed the rename marker.Behavior change
describe()on a table with an enum whose values contain a colon prints a definition that declares the same table. Before, the enum was cut at the first colon.alter()on such a table used to stop withUnsupported attribute type enum('10 ..., because the definition read back from the database did not parse, and made no change. It now runs. A rename of such an attribute is aCHANGEon MySQL, which keeps the values. On PostgreSQL,alter()refuses the rename and makes no change, as it does for any other attribute.declare.pychange, the heading fix alone would have letalter()miss the rename marker on such an attribute and drop the attribute and add it again empty. Both changes ship together in this PR.Tests
tests/unit/test_type_comment.py::enum('10:00','11:00'):start of slotgives the typeenum('10:00','11:00')and the commentstart of slot. Other cases: a colon in a value followed by a comment with colons, a doubled quote inside a value, and an apostrophe in the comment after a plain type. A quoted value with a line break, an unclosed quote, and a quoted type name all stay plain comments.tests/integration/test_type_comment.py, on MySQL and PostgreSQL: a table with two such enums reads back the rightoriginal_typeandcomment, a table declared fromdescribe()matches the original declaration, and values insert and fetch unchanged.tests/integration/test_alter_rename.py::test_rename_enum_with_colon_keeps_values, on MySQL and PostgreSQL, for a required and a nullable attribute: anenum('10:00','11:00')attribute holding two rows is renamed with{start}. On MySQL the values and the declared type are kept under the new name. On PostgreSQLalter()raises the rename error and the values stay in place.declare.pychange, all four cases of the newalter()test fail: on MySQL every row ends up'10:00'(required) or NULL (nullable), and on PostgreSQL the nullable attribute is dropped and added again empty with no error. On master they fail with theUnsupported attribute typeerror.