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

Improve TrinoStatementExecError #4842

Merged
merged 6 commits into from
Jan 5, 2024
Merged

Improve TrinoStatementExecError #4842

merged 6 commits into from
Jan 5, 2024

Conversation

samdoran
Copy link
Contributor

Description

Improve the TrinoStatementExecError class to behave more like the exceptions from trino.exceptions.
Use the __str__ method for message formatting.
Make attributes of the underlying TrinoQueryError available as properties of TrinoStatementExecError. This allows for more precise error handling based on the specific type of Trino error rather than having to match on strings in the error message.
Rename some one character variables.

Testing

tox -e py39 -- koku.test_trino_db_utils

@samdoran samdoran added the smoke-tests pr_check will build the image and run minimal required smokes label Dec 19, 2023
@samdoran samdoran requested review from a team as code owners December 19, 2023 22:21
Copy link

codecov bot commented Dec 19, 2023

Codecov Report

Merging #4842 (4c1f85c) into main (85284b1) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #4842   +/-   ##
=====================================
  Coverage   94.0%   94.0%           
=====================================
  Files        364     365    +1     
  Lines      30214   30288   +74     
  Branches    3599    3603    +4     
=====================================
+ Hits       28389   28465   +76     
+ Misses      1162    1159    -3     
- Partials     663     664    +1     

cgoodfred
cgoodfred previously approved these changes Dec 20, 2023
@samdoran samdoran enabled auto-merge (squash) December 20, 2023 18:30
- Require parameters that are useful when handling this exception type
- Expose the underlying TrinoQueryError directly
- Use the __str__ method for formatting the error code
- Use implicit string concatenation
- Don’t import the whole module
- Correct repr
- Increase coverage of trino_database.py
@@ -105,6 +134,44 @@ def cursor(self):
select x from y;
select a from b;
"""
with self.assertRaises(trino_db.TrinoStatementExecError):
with self.assertRaises(ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick question: Curious why this is now a ValueError from TrinoStatementExecError?

Copy link
Contributor Author

@samdoran samdoran Dec 21, 2023

Choose a reason for hiding this comment

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

I was hoping someone would ask about that. I changed the behavior in executescript() to only raise TrinoStatementExecError if a TrinoQueryError was raised since that is now a required parameter of TrinoStatementExecError. Otherwise, just raise the original exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation 👍🏾 , and I see the ValueError raised by FakerFakeTrinoConn

Copy link
Contributor

@djnakabaale djnakabaale left a comment

Choose a reason for hiding this comment

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

lgtm 👍🏾

@samdoran samdoran enabled auto-merge (squash) January 5, 2024 22:35
Copy link

sonarcloud bot commented Jan 5, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@samdoran samdoran merged commit 97d4b19 into main Jan 5, 2024
10 checks passed
@samdoran samdoran deleted the improve-trino-exception branch January 5, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smoke-tests pr_check will build the image and run minimal required smokes smokes-required
Projects
None yet
4 participants