Repository navigation
grass.pygrass: Add the psycopg2 hint as an exception note - #7690
Merged
Merged
Conversation
The table connection raised a new ImportError with the hint as its message, so the message of the original error, which says which module is missing, was replaced by the hint. Add the hint as a note to the original error instead. From the Python documentation of BaseException.add_note(): "Add the string note to the exception's notes which appear in the standard traceback after the exception string." The traceback then shows both the missing module and the hint. Exception notes need Python 3.11, which is now the minimum version.
echoix
approved these changes
Jul 14, 2026
echoix
left a comment
Member
There was a problem hiding this comment.
Perfect! Needed Python 3.11, now it is there, and follows the Python docs.
echoix
pushed a commit
to wenzeslaus/grass
that referenced
this pull request
Jul 14, 2026
The table connection raised a new ImportError with the hint as its message, so the message of the original error, which says which module is missing, was replaced by the hint. Add the hint as a note to the original error instead. From the Python documentation of BaseException.add_note(): Add the string note to the exception's notes which appear in the standard traceback after the exception string. The traceback then shows both the missing module and the hint. Exception notes need Python 3.11, which is now the minimum version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now, the table connection raises a new
ImportErrorwith the hint as its message, so a missing psycopg2 ends in a pair of chained exceptions ("During handling of the above exception, another exception occurred").Add the hint as a note to the original error instead. From the Python documentation of
BaseException.add_note(): "Add the stringnoteto the exception's notes which appear in the standard traceback after the exception string."Connecting to a PostgreSQL table without psycopg2 then gives a single exception with the actual error as its message and the hint after it:
The error is not caught anywhere, so it reaches a traceback, which is where a note is shown. It would not be shown if a caller printed
str(exception).This is the case discussed in #4032 (
table.py:865), which was waiting for Python 3.11 as the minimum version. It touches the same lines as #4032, so whichever is merged second needs a trivial conflict resolution.