Skip to content

Cast row_limit as integer#448

Merged
ellbosch merged 7 commits intomasterfrom
ellbosch/row-limit-bug
Apr 12, 2020
Merged

Cast row_limit as integer#448
ellbosch merged 7 commits intomasterfrom
ellbosch/row-limit-bug

Conversation

@ellbosch
Copy link
Copy Markdown
Collaborator

@ellbosch ellbosch commented Apr 8, 2020

Fixes #444.

The --row-limit arg was breaking mssql-cli because our code attempted to use a number operator on a string. The fix requires casting the parsed option as an integer.

Notes:

  • row_limit is validated in the MssqlCli constructor, which uses a new _set_row_limit method to validate a positive integer.
  • _set_row_limit calls sys.exit(1) if an invalid value is provided.
  • As a consequence to the above, we needed to catch an AttributeException in the __del__ method because shutdown is called on an uninstantiated sqltoolsclient.
  • Testing included to hopefully prevent issues like this in the future.

Comment thread mssqlcli/mssql_cli.py Outdated
else:
self.row_limit = c['main'].as_int('row_limit')

self.row_limit = \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the right layer/place to make the fix? This seems like an option parsing concern and perhaps handled by argparse?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So we definitely can add a check in argparse. However, we may want to keep logic elsewhere because we also accept a value from our config if there's no value for the --row-limit arg. Where that somewhere should be is open for debate.

I've considered main.py and the current location in mssqlcli.py. I picked the current location due to easier testability, also it seems like good design to have the constructor handle this logic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's fix this to args parse for now - seems like the right place.

Looks like a there are a number of issues reading values from our config so let's fix those in another PR at a later date.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I take back my prior statement—I was able to move logic for checking the config value right in argparse. It seems to work well, once tests pass I'll update the PR.

Comment thread mssqlcli/mssql_cli.py Outdated
try:
# try/except block needed if shutdown is invoked before sqltoolsclient is defined.
# example: invalid row-limit argument is passed.
if self.sqltoolsclient:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes me nervous. In what situations will we raise an AttributeError?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

AttributeError is raised f the MssqlCli constructor exits due to invalid parameters. In this case, say we input a series of characters instead of an integer for --row-limit—we exit during class instantiation, and before sqltoolsclient gets instantiated. Therefore the class doesn't possess the sqltoolsclient attribute, thus raising an AttributeError.

Comment thread mssqlcli/mssqlclioptionsparser.py Outdated

return args_parser

def check_positive_int(row_limit):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add 'row_limit' to the method name? This way, it stands out from being a generic 'check_positive_int' method. Ideally, we have a generic method where check_row_limit calls check_positive_int('row_limit' value), and check positive can be resused.

@ellbosch
Copy link
Copy Markdown
Collaborator Author

I'm fairly certain recent failures are due to PR validation build pipelines using the master DB, which tests in this branch don't support. Best we wait until #441 is approved.

@pensivebrian
Copy link
Copy Markdown
Member

Can you clarify what you mean by master db? master db should be read only, and tests should use their own database.

@ellbosch
Copy link
Copy Markdown
Collaborator Author

Can you clarify what you mean by master db? master db should be read only, and tests should use their own database.

Correct—with our stabilize DB PR, tests now generate a test DB if performing operations off of a database. Some tests were still performing commands off of the permanent DB we created, but that will all change once we merge #441.

In anticipation of this change, I set up or PR validation pipelines to no longer use the permanent DB, so we could properly test #441. This impacts other PRs (like this one) so it's best we wait to merge until #441 is complete.

@ellbosch ellbosch force-pushed the ellbosch/row-limit-bug branch from 12f5c56 to b768690 Compare April 11, 2020 02:34
@ellbosch ellbosch merged commit f418b15 into master Apr 12, 2020
@ellbosch ellbosch deleted the ellbosch/row-limit-bug branch April 13, 2020 14:53
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.

Crash when displaying results if --row-limit is specified

2 participants