-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Update table PATCH endpoint to work with columns #578
Conversation
@eito-fis @powellc and anyone else interested in backend code: I'm working on supporting a bunch of different operations in one transaction in this PR. it seems to work, but the way I got it to work is by updating a bunch of functions to take Any suggestions/thoughts would be appreciated |
The sqlalchemy documentation has some suggestion for dealing with the nested transaction pattern, which seem reasonable, if not much different from what we have now. If we're alright with digging into some of the internals, I think we could also try extending the Wrt to the table, I don't have a great solution. Maybe just a function that takes a table and OID, either of which could be |
Thanks @eito-fis! Those are all good ideas, I'll think about it and figure out an approach. |
Please see the following issues for follow up work related to this issue: |
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.
Merging this PR, as it is blocking work on the frontend. Review changes, if any, will be taken up as a separate PR.
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.
Looks great! Just a couple small comments.
return False | ||
|
||
|
||
def retype_column_in_connection(table, connection, engine, column_index, new_type, type_options={}): |
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.
Why do we create a new function here instead of using the connection_to_use=None, table_to_use=None
pattern used elsewhere?
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.
I was trying out different patterns to figure out which one might work better, I'll refactor this to be more consistent with the other functions.
columns.set_column_default(table_oid, column_index, new_default, engine) | ||
default_stmt = select(text(cast_stmt)) | ||
new_default = str(execute_statement(engine, default_stmt, connection_to_use).first()[0]) | ||
columns.set_column_default(table_oid, column_index, new_default, engine, connection_to_use) |
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.
Should this also pass table_to_use
?
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.
Nice catch, thanks!
assert updated_table.columns[index].name == column_data[index - 2]['name'] | ||
|
||
|
||
def test_batch_update_column_all_operations(engine_email_type): |
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.
Really like these tests 👍
def _check_columns(actual_column_list, expected_column_list): | ||
# Columns will return an extra type_options key in actual_dict | ||
# so we need to check equality only for the keys in expect_dict | ||
for index, column_dict in enumerate(expected_column_list): |
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.
Small nitpick, it might be nicer to iterate over a zip of the two lists.
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.
Agreed, I'll make the change. Thanks!
Fixes #562
The table detail API now accepts
columns
as a valid key in aPATCH
request. It will updates names and types of columns as well as drop columns. It takes the same options as the table previews endpoint.Note to reviewers
Please expand the
test_table_api.py
file, GitHub is hiding it by default as a "large diff".Technical details
In order to get multiple operations to happen within a single transaction, we're passing
connection
andtable
objects around. This code is a little messy, but I didn't want to hold this up since it's blocking our next milestone so I created a new issue to refactor it. I also created a separate issue to look into whether we can support altering the table's name in the same request as altering columns.db
code to work with existing connections #592PATCH
requests to the Table API should support changing the table's name and columns at the same time #593Work done in this PR
PATCH
endpoint to handle updating column names and typesPATCH
function to also handle dropping columnsretype
function.db
levelChecklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin