Skip to content

fix(alter): keep an attribute's values when alter() renames it (2.3) - #1635

Merged
dimitri-yatsenko merged 1 commit into
maint/2.3from
fix/alter-rename-keeps-data-2.3
Oct 21, 2026
Merged

dimitri-yatsenko merged 1 commit into
maint/2.3from
fix/alter-rename-keeps-data-2.3

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Backport of #1634 to maint/2.3 for 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, 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.

Fixes #1631.

`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 dimitri-yatsenko added this to the v2.3.5 milestone Oct 18, 2026
@dimitri-yatsenko dimitri-yatsenko added the bug Indicates an unexpected problem or unintended behavior label Oct 18, 2026
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Merging on the strength of #1634's review: this is the same commit, cherry-picked to maint/2.3 for v2.3.5, and its CI passes.

@dimitri-yatsenko
dimitri-yatsenko merged commit 1ba8b9f into maint/2.3 Oct 21, 2026
9 checks passed
@dimitri-yatsenko
dimitri-yatsenko deleted the fix/alter-rename-keeps-data-2.3 branch October 21, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant