refactor: Repeated boilerplate code between upload to database forms#16756
refactor: Repeated boilerplate code between upload to database forms#16756villebro merged 18 commits intoapache:masterfrom
Conversation
|
❗ Please consider rebasing your branch to avoid db migration conflicts. |
1 similar comment
|
❗ Please consider rebasing your branch to avoid db migration conflicts. |
Codecov Report
@@ Coverage Diff @@
## master #16756 +/- ##
==========================================
- Coverage 76.89% 76.68% -0.22%
==========================================
Files 1038 1038
Lines 55515 55494 -21
Branches 7564 7564
==========================================
- Hits 42690 42556 -134
- Misses 12575 12688 +113
Partials 250 250
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
@villebro do you mind taking a look when you get a chance? |
|
❗ Please consider rebasing your branch to avoid db migration conflicts. |
villebro
left a comment
There was a problem hiding this comment.
One question on the db migration (also, this needs a rebase). I think it may be safer to leave the column name in dbs as-is and only change the rest of the codebase so that we can avoid a database migration.
| def upgrade(): | ||
| with op.batch_alter_table("dbs") as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "allow_file_upload", | ||
| sa.Boolean(), | ||
| nullable=False, | ||
| server_default=expression.true(), | ||
| ) | ||
| ) | ||
| batch_op.drop_column("allow_csv_upload") |
There was a problem hiding this comment.
Wouldn't this remove all existing allow_csv_upload values and set the new allow_file_upload to TRUE?
There was a problem hiding this comment.
Instead of adding and dropping the columns, I think we can go with this renaming pattern instead:
| def upgrade(): | |
| with op.batch_alter_table("dbs") as batch_op: | |
| batch_op.add_column( | |
| sa.Column( | |
| "allow_file_upload", | |
| sa.Boolean(), | |
| nullable=False, | |
| server_default=expression.true(), | |
| ) | |
| ) | |
| batch_op.drop_column("allow_csv_upload") | |
| def upgrade(): | |
| with op.batch_alter_table("dbs") as batch_op: | |
| batch_op.alter_column("allow_csv_upload", new_column_name="allow_file_upload") |
| class ExcelToDatabaseForm(DynamicForm): | ||
| # pylint: disable=E0211 | ||
| def excel_allowed_dbs() -> List[Database]: # type: ignore | ||
| # TODO: change allow_csv_upload to allow_file_upload |
There was a problem hiding this comment.
This is a longstanding TODO so I do think we should go ahead with the db migration.
| def upgrade(): | ||
| with op.batch_alter_table("dbs") as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "allow_file_upload", | ||
| sa.Boolean(), | ||
| nullable=False, | ||
| server_default=expression.true(), | ||
| ) | ||
| ) | ||
| batch_op.drop_column("allow_csv_upload") |
There was a problem hiding this comment.
Instead of adding and dropping the columns, I think we can go with this renaming pattern instead:
| def upgrade(): | |
| with op.batch_alter_table("dbs") as batch_op: | |
| batch_op.add_column( | |
| sa.Column( | |
| "allow_file_upload", | |
| sa.Boolean(), | |
| nullable=False, | |
| server_default=expression.true(), | |
| ) | |
| ) | |
| batch_op.drop_column("allow_csv_upload") | |
| def upgrade(): | |
| with op.batch_alter_table("dbs") as batch_op: | |
| batch_op.alter_column("allow_csv_upload", new_column_name="allow_file_upload") |
|
❗ Please consider rebasing your branch to avoid db migration conflicts. |
…erplate_and_rename
…/superset into boilerplate_and_rename
|
@villebro can you take another look? |
|
Thanks @exemplary-citizen, sorry for the delay, I'll give this a new review + test as soon as I have some spare time (hoping to do it this week). |
villebro
left a comment
There was a problem hiding this comment.
This is great work @exemplary-citizen ! LGTM and tested to work well!
|
This migration is failing on MySQL for me, for some reason: Looks like it happens in MySQL 8: sqlalchemy/alembic#699 |
|
@betodealmeida @exemplary-citizen @villebro it seems like there should be an entry in |
|
Also @betodealmeida @exemplary-citizen @villebro the current migration is not suffice. The |
|
@john-bodley just opened #17294. feel free to assign to me. I'll start working on a fix |
|
Thanks @exemplary-citizen. I've assigned the issue to you. Feel free to add me as a reviewer and/or ping me in Slack—given that most of my GitHub mentions seem to get lost in the aether. |
|
Another problem with this PR that I missed: it changed a versioned schema ( (Not complaining or assigning blame, just calling it out so we catch these things in the future.) |
|
Sorry for being late the the discussion. @betodealmeida @john-bodley thanks for calling out. |
SUMMARY
There's unnecessary duplication here between CSV and other forms.
Instead we can abstract this into a class
UploadToDatabaseForm(DynamicForm)with all the repeated boilerplate and then extend those into classCsvToDatabaseForm(UploadToDatabaseForm), classExcelToDatabaseForm(UploadToDatabaseForm)etc.TESTING INSTRUCTIONS
Watch CI and any suggestions from reviewers
ADDITIONAL INFORMATION
Fixes #16046
cc: @villebro