Repository navigation
Preserve empty string comments on create table and add column #1871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+138
−13
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01f4d84
Preserve empty string comments on create table and add column
vineoy 1ce026e
Add empty comment render and compare tests for #1085
vineoy 60ffb5a
Use normalize_comment impl hook for Oracle empty string handling
vineoy c0c50f3
test: move imports to module level in empty comment tests
vineoy 5eacb86
Move empty comment compare tests to backend CompareCommentTest
vineoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1400,6 +1400,17 @@ def test_render_col_with_comment(self): | |
| "comment='This is a comment')", | ||
| ) | ||
|
|
||
| def test_render_col_with_empty_comment(self): | ||
| c = Column("some_key", Integer, comment="") | ||
| Table("some_table", MetaData(), c) | ||
| result = autogenerate.render._render_column(c, self.autogen_context) | ||
| eq_ignore_whitespace( | ||
| result, | ||
| "sa.Column('some_key', sa.Integer(), " | ||
| "nullable=True, " | ||
| "comment='')", | ||
| ) | ||
|
|
||
| def test_render_col_comment_with_quote(self): | ||
| c = Column("some_key", Integer, comment="This is a john's comment") | ||
| Table("some_table", MetaData(), c) | ||
|
|
@@ -2299,6 +2310,24 @@ def test_render_table_with_comment(self): | |
| ")", | ||
| ) | ||
|
|
||
| def test_render_table_with_empty_comment(self): | ||
| m = MetaData() | ||
| t = Table( | ||
| "test", | ||
| m, | ||
| Column("id", Integer, primary_key=True, comment=""), | ||
| comment="", | ||
| ) | ||
| op_obj = ops.CreateTableOp.from_table(t) | ||
| eq_ignore_whitespace( | ||
| autogenerate.render_op_text(self.autogen_context, op_obj), | ||
| "op.create_table('test'," | ||
| "sa.Column('id', sa.Integer(), nullable=False, comment='')," | ||
| "sa.PrimaryKeyConstraint('id')," | ||
| "comment=''" | ||
| ")", | ||
| ) | ||
|
|
||
| def test_render_table_with_info(self): | ||
| m = MetaData() | ||
| t = Table( | ||
|
|
@@ -2330,6 +2359,14 @@ def test_render_add_column_with_comment(self): | |
| "nullable=True, comment='This is a Column'))", | ||
| ) | ||
|
|
||
| def test_render_add_column_with_empty_comment(self): | ||
| op_obj = ops.AddColumnOp("foo", Column("x", Integer, comment="")) | ||
| eq_ignore_whitespace( | ||
| autogenerate.render_op_text(self.autogen_context, op_obj), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Michael Bayer (zzzeek) wrote: absoutely part of autogen_diffs, it's testing _compare_column_comment so that's diffs View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/7016 |
||
| "op.add_column('foo', sa.Column('x', sa.Integer(), " | ||
| "nullable=True, comment=''))", | ||
| ) | ||
|
|
||
| def test_render_create_table_comment_op(self): | ||
| op_obj = ops.CreateTableCommentOp("table_name", "comment") | ||
| eq_ignore_whitespace( | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Robot 1 (ai-robot-1) wrote:
Done in patch set 4. These tests are now in alembic/testing/suite/test_autogen_comments.py, and tests/test_autogen_diffs.py is back to its main-branch state.
On real databases, Oracle isn't the only backend where an empty comment can't be stored. PostgreSQL drops the comment on COMMENT ON ... IS '', and MySQL/MariaDB treat an empty comment as no comment. All three reflect comment='' back as None. That is why the earlier compare tests failed on PostgreSQL, MySQL and MSSQL in CI. So instead of an Oracle-only test, there are two suite classes:
allows_empty_comments(SQL Server). The table-level tests here also requireallows_empty_table_comments, which is currently off because SQLAlchemy's mssql dialect reflects an empty table comment as None.empty_comments_are_null(PostgreSQL, MySQL, MariaDB, Oracle). It checks that '' vs None produces no diff.On the implementation side, DefaultImpl has a new
supports_empty_commentsflag, set to False for the PostgreSQL, MySQL and Oracle impls, and normalize_comment() maps '' to None when the flag is False.View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/7016