Repository navigation
Fix unicode issues - #671
Merged
evertlammerts merged 4 commits intoOct 16, 2026
Merged
evertlammerts merged 4 commits into
evertlammerts merged 4 commits into
Conversation
evertlammerts
force-pushed
the
fix-lone-surrogate-parameter
branch
from
October 15, 2026 20:58
5d68906 to
316aa69
Compare
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.
A Python str that UTF-8 cannot encode, such as
"\ud800", failed on every value path withRuntimeError: std::bad_cast:execute("SELECT ?", ["\ud800"]),executemany,sql(params=),duckdb.Value, lists, dicts and maps,ConstantExpression,values, native UDF return values. In apandas or numpy object column it was worse: the scan handed the surrogate to an engine helper, which
raised an INTERNAL error and invalidated the whole database:
Both happened on 1.5.6 as well (there the first message was pybind11's "Unable to cast Python instance").
Root cause: nanobind's string caster clears the UnicodeEncodeError and reports a failed cast, so the
reason was lost at the first conversion; the object column scan decoded code points itself and never
checked for the surrogate range.
Changes:
TransformPythonStringconverts a str with the same CPython call nanobind uses and, on aUnicodeEncodeError, raises
InvalidInputException: Python Conversion Failure: cannot encode str as UTF-8, surrogate '\udXXX' at position N is not allowed. Used by the value converter, numpy<Uenumentries, object category entries, and the
read_csvna_values,delimiterandsepandwrite_csvna_repoptions. Valid strs take the same path as before.DecodePythonUnicode) computes UTF-8 lengths and encodes inline, raising thesame error on a surrogate. It no longer calls the engine's per code point helpers, which also makes
scans of non ASCII object columns without cached UTF-8 about 2x faster (measured on Release builds
against the base; every other case is within noise).
Not changed: a str used as a name (a dict key becoming a field name, a named parameter name, SQL text)
still fails as before;
duckdb.Valuestill checks nothing at construction. A str subclass such asnumpy.str_with non ASCII text in an object column fails with an unrelated error, as on 1.5.6.