-
Notifications
You must be signed in to change notification settings - Fork 179
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
chore(robot-server, api): filter fixit commands out of the commands list #16075
chore(robot-server, api): filter fixit commands out of the commands list #16075
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## edge #16075 +/- ##
===========================================
+ Coverage 56.21% 92.43% +36.22%
===========================================
Files 32 77 +45
Lines 1681 1283 -398
===========================================
+ Hits 945 1186 +241
+ Misses 736 97 -639
Flags with carried forward coverage won't be shown. Click here to find out more. |
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 know this is a work in progress, just some preliminary comments:
… - using intent instead of command_intent
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 good, need to remove all that commented out test code though.
Do we need both those command_intent != 'fixit' OR command_intent == None
things there? shouldn't fixit != none? isn't that column non-nullable anyway?
robot-server/tests/integration/http_api/persistence/test_compatibility.py
Outdated
Show resolved
Hide resolved
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.
Sweet!
for old_row in source_transaction.execute(select_old_protocols).all(): | ||
new_protocol_kind = ( | ||
schema_6.ProtocolKindSQLEnum.STANDARD.value | ||
if old_row.protocol_kind == "<ProtocolKindSQLEnum.STANDARD: 'standard'>" | ||
else schema_6.ProtocolKindSQLEnum.QUICK_TRANSFER.value | ||
) |
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.
We spoke a bit about this yesterday, can you go over why we need to do this?
The change that added ProtocolKindSQLEnum converts the stored values for protocol_kind from plain strings to SQLEnums like so "<ProtocolKindSQLEnum.STANDARD: 'standard'>". While this is stored on the database in the above format, when you use sqlalchemy to query it returns an actual enum object.
So we don't want to store the plain string values "quick-transfer" and "standard" but <ProtocolKindSQLEnum.QUICK_TRANSFER: 'quick-transfer'>
and <ProtocolKindSQLEnum.STANDARD: 'standard'>
as we have now.
Furthermore, we added this migration step to account for NULL protocol_kind values, which are semantically equal to the "standard" protocol kind in DB schema V5. This change would revert that.
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.
What @vegano1 said. The protocol table should be copied unmodified. There is nothing wrong with the protocol kind column's contents in v6 database.
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.
if we store the string values we are still able to parse as ProtocolKindSQLEnum. if you will take a look at the code lambda obj: [e.value for e in obj]
should insert the value of the enum in the DB but instead its storing the member. The problem I encountered is that bc we store <ProtocolKindSQLEnum.QUICK_TRANSFER: 'quick-transfer'> when migrating and copying over the row's ProtocolKindSQLEnum
does not know how to parse this value. its expecting quick-transfer
. @sanni-t @vegano1
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.
values_callable –
A callable which will be passed the PEP-435 compliant enumerated type, which should then return a list of string
values to be persisted. This allows for alternate usages such as using the string value of an enum to be persisted to the database instead of its name.
from documentation. https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.Enum
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.
Left a comment regarding quick transfers protol_kind key in the database.
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 definitely change the protocol table migration to copy it unmodified.
Other than that I think there has to be an easier way to migrate when only adding a column to the table (like what we do in v4 to v5 migration) but it's a soft suggestion. If this is blocking something then we don't have to make that optimization in this PR.
for old_row in source_transaction.execute(select_old_protocols).all(): | ||
new_protocol_kind = ( | ||
schema_6.ProtocolKindSQLEnum.STANDARD.value | ||
if old_row.protocol_kind == "<ProtocolKindSQLEnum.STANDARD: 'standard'>" | ||
else schema_6.ProtocolKindSQLEnum.QUICK_TRANSFER.value | ||
) |
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.
What @vegano1 said. The protocol table should be copied unmodified. There is nothing wrong with the protocol kind column's contents in v6 database.
source_transaction = exit_stack.enter_context(source_engine.begin()) | ||
dest_transaction = exit_stack.enter_context(dest_engine.begin()) | ||
|
||
_migrate_db_with_changes(source_transaction, dest_transaction) |
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.
Copying over unmodified tables individually work, but I wonder if there's an easier way of doing what you want. You are just adding a column to a table and inserting its contents. There should be a way to just copy over the entire .db file, then open it up with the new schema, add a column and insert contents for the new column.
The method in this PR is not wrong, but feels like we are doing too much work for just adding a column. Also, it's easy to forget to copy over tables and files when doing such individual copying.
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 agree but its not just adding a column. Its selecting the command as a json and extracting data from it. I agree, if it was just a simple SQL server I would have probably just ALTER and UPDATE, but its a bit more complicated when using json objects.
sqlalchemy.Column("index_in_run", sqlalchemy.Integer, nullable=False), | ||
sqlalchemy.Column("command_id", sqlalchemy.String, nullable=False), | ||
sqlalchemy.Column("command", sqlalchemy.String, nullable=False), | ||
sqlalchemy.Column("command_intent", sqlalchemy.String, nullable=False, index=True), |
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 can see the usefulness of creating an index on this, but it doesn't look like we are using it when selecting commands, are we? Not saying that this column shouldn't be indexed, just want to check if we are planning on using the index.
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.
we are using command_intent
in the where clause when slicing historical run commands
tested migrations! works perfectly! tested changes in route - works as expected |
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.
Yay! I'm glad we were able to figure out the enum weirdness and reduce the steps needed to do the migration.
Have a nitpick and a question. Otherwise the db changes lgtm!
engine.execute( | ||
f"ALTER TABLE {table_name} ADD COLUMN {column.key} {column_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.
Does this get committed in the same transaction as the table update? I get confused with the different ways execute
can be called and what it implies. Just want to be sure that it's one transaction.
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 be the same transaction
Overview
reference #16001 for previous pr comments.
closes EXEC-654.
get filtered command list for historical runs and for current runs.
Test Plan and Hands on Testing
Changelog
includeFixitCommands
toget_run_commands
route.CommandState
andCommandHistory
to filter based on the protocol intent.command_intent
torun_command_table
and migration scripts.Review requests
changes make sense? how ugly is this?
Risk assessment
Medium. need to make sure run commands did not changed the default behavior.