Repository navigation
Conversation
When a character column holds bytes that cannot be decoded, for example a lone UTF-16 surrogate stored by older drivers that cut an emoji in half on insert, the conversion to str fails. fetch_assoc(), fetch_both(), fetchmany() and fetchall() already raise UnicodeDecodeError in that case, but fetch_tuple() and fetchone() returned the row with the error still set, so Python raised SystemError, and result() passed the failed conversion to a debug log call and crashed. All of them now raise UnicodeDecodeError. Add a regression test. Signed-off-by: Robert Cope <robert@copesystems.com>
Earammak
approved these changes
Nov 17, 2026
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.
When converting a character column to
strfails (for example a lone UTF-16 surrogate stored by drivers before #1065), every fetch API now raises theUnicodeDecodeError, asfetch_assoc(),fetch_both(),fetchmany()andfetchall()(and their DBI counterparts) already did:_python_ibm_db_bind_fetch_helper()(fetch_tuple()/fetchone()): return NULL instead of storing the NULL value in the row tuple and returning the tuple with the error pending (SystemError).ibm_db_fetchone(): propagate that error instead of returningNoneover it.ibm_db_result(): skip the debug log line when the conversion failed. It passed the NULL result toPyUnicode_AsUTF8()and crashed.No characters are replaced or substituted, and nothing changes for values that decode.
Closes #1088
Added
ibm_db_tests/test_6797_FetchUndecodableText.py. It runs against Db2 LUW and needs a UTF-8 database, like the other emoji tests. It inserts the undecodable bytes through aFOR BIT DATAcast, checksfetch_tuple(),fetch_assoc(),fetch_both(),result(),fetchone(),fetchmany(),fetchall()and DBIfetchone()/fetchmany()/fetchall(), and then checks that a valid row on the same connection still reads.Testing (Linux x86_64, Python 3.13, clidriver v11.5.9, Db2 LUW 11.5.8):
result()case). With this change it passes.