Skip to content
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

Merged

Conversation

TamarZanzouri
Copy link
Contributor

@TamarZanzouri TamarZanzouri commented Aug 20, 2024

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

  • upload a protocol that will enter ER.
  • add some fixit commands.
  • make sure you dont see the fixit commands in the run log.
  • when the run is completed and un-current make sure you still dont see fixit commands.

Changelog

  • added an arg includeFixitCommands to get_run_commands route.
  • add logic to CommandState and CommandHistory to filter based on the protocol intent.
  • added column command_intent to run_command_table and migration scripts.
  • fixed but with copying over enum columns in the DB.
  • added filtering in the sql query for command intent.

Review requests

changes make sense? how ugly is this?

Risk assessment

Medium. need to make sure run commands did not changed the default behavior.

@TamarZanzouri TamarZanzouri requested a review from a team as a code owner August 20, 2024 20:03
@TamarZanzouri TamarZanzouri marked this pull request as draft August 20, 2024 20:03
Copy link

codecov bot commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.43%. Comparing base (3f48d03) to head (1d4d990).
Report is 201 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
g-code-testing 92.43% <ø> (?)
update-server ?
usb-bridge ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 109 files with indirect coverage changes

Copy link
Contributor

@SyntaxColoring SyntaxColoring left a 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:

@TamarZanzouri TamarZanzouri changed the title Exec 686 filter fixit commands out of the commands list chore(robot-server, api): filter fixit commands out of the commands list Sep 10, 2024
@TamarZanzouri TamarZanzouri marked this pull request as ready for review September 10, 2024 17:38
Copy link
Member

@sfoster1 sfoster1 left a 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?

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

Comment on lines 107 to 112
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
)
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

@TamarZanzouri TamarZanzouri Sep 11, 2024

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

Copy link
Contributor Author

@TamarZanzouri TamarZanzouri Sep 11, 2024

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

Copy link
Contributor

@vegano1 vegano1 left a 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.

Copy link
Member

@sanni-t sanni-t left a 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.

Comment on lines 107 to 112
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
)
Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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),
Copy link
Member

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.

Copy link
Contributor Author

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

@TamarZanzouri
Copy link
Contributor Author

tested migrations! works perfectly! tested changes in route - works as expected

Copy link
Member

@sanni-t sanni-t left a 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!

Comment on lines +54 to +56
engine.execute(
f"ALTER TABLE {table_name} ADD COLUMN {column.key} {column_type}"
)
Copy link
Member

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.

Copy link
Contributor Author

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

@TamarZanzouri TamarZanzouri merged commit b2ba38e into edge Sep 13, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants