Repository navigation
fix(alter): keep an attribute's values when alter() renames it (2.3) - #1635
Open
dimitri-yatsenko wants to merge 1 commit into
Open
dimitri-yatsenko wants to merge 1 commit into
dimitri-yatsenko wants to merge 1 commit into
Conversation
`alter()` renames an attribute whose new comment opens with `{old_name}`. It looked for that marker in the compiled column SQL, where it is not always found. A core type or codec writes its `:type:` marker in front of the comment (`COMMENT ":float32:{value} ..."`), and PostgreSQL keeps comments out of the column SQL altogether. In both cases the rename went unnoticed: `alter()` dropped the old attribute and added the new one, and every value was lost. On MySQL, renaming `value : float32` to `reading : float32 # {value}` left `reading` at 0.0 in every row; on PostgreSQL, renaming a nullable attribute left it NULL. A required attribute on PostgreSQL failed with a NOT NULL error instead.
The marker is now read from the comment as declared, after any `:type:` marker. On MySQL the rename becomes a CHANGE, which keeps the values. PostgreSQL has no CHANGE, so `alter()` now refuses a rename there with a DataJointError before running anything, instead of dropping the attribute.
The new tests rename a required and a nullable core-type attribute of a table holding rows. On MySQL they check that the values survive; on PostgreSQL that the rename is refused and the table keeps its values. All four fail before this change.
(cherry picked from commit 6657b23)
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
October 18, 2026 00:30
This branch has not been deployed
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.
Backport of #1634 to
maint/2.3for v2.3.5, cherry-picked unchanged.alter()renames an attribute whose new comment opens with{old_name}. It looked for that marker in the compiled column SQL, where it is not always found. A core type or codec writes its:type:marker in front of the comment (COMMENT ":float32:{value} ..."), and PostgreSQL keeps comments out of the column SQL altogether. In both cases the rename went unnoticed:alter()dropped the old attribute and added the new one, and every value was lost. On MySQL, renamingvalue : float32toreading : float32 # {value}leftreadingat 0.0 in every row; on PostgreSQL, renaming a nullable attribute left it NULL. A required attribute on PostgreSQL failed with a NOT NULL error instead.The marker is now read from the comment as declared, after any
:type:marker. On MySQL the rename becomes a CHANGE, which keeps the values. PostgreSQL has no CHANGE, soalter()now refuses a rename there with a DataJointError before running anything, instead of dropping the attribute.The new tests rename a required and a nullable core-type attribute of a table holding rows. On MySQL they check that the values survive; on PostgreSQL that the rename is refused and the table keeps its values. All four fail before this change.
Fixes #1631.