Repository navigation
fix(sqlalchemy-bigquery): restore String bindparam type for GeoAlchemy2 0.21.0 - #18985
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the BigQuery geography compiler to support GeoAlchemy2 >= 0.21.0 by restoring the String type for string bind parameters wrapped in NullType, and registers the fixup hook on all GenericFunction subclasses. The review feedback recommends wrapping the subclass registration in a try-except block to prevent import errors in environments where geoalchemy2 is not installed.
parthea
reviewed
Nov 4, 2026
parthea
approved these changes
Nov 4, 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.
Problem / Context
In
GeoAlchemy2 >= 0.21.0,GenericFunction.__init__wraps raw string arguments (isinstance(elem, str)) in an_UntypedString(NullType)bind parameter so PostgreSQL drivers send raw strings untyped.In
sqlalchemy-bigquery:_fixup_st_argumentsonly overridesBindParameter.typefor functions registered in_argument_types(which maps functions expectingGEOGRAPHYparameters). For geography constructor functions that accept aSTRINGargument (such asST_GeogFromText), theBindParameter.typeremains_UntypedString(NullType).@compileshandlers (e.g., for"mssql") onGenericFunctionsubclasses such asST_GeogFromText, giving those subclasses their own_compiler_dispatcherthat shadowsGenericFunction._compiler_dispatcher.When
BigQueryCompiler.visit_bindparaminspects aNullTypebind parameter, it returns%(ST_GeogFromText_1)swithout the:STRINGtype suffix, breakingsqlalchemy-bigquery's typed bind parameter contract and unit tests (test_geoalchemy2_coreandtest_calling_st_functions_that_dont_take_geographies).Solution
packages/sqlalchemy-bigquery/sqlalchemy_bigquery/geography.py:_fixup_st_arguments, restoreargument.type = sqlalchemy.types.String()for anyBindParameterwhosetypeisNullTypeand whosevalueis astrprior to applying_argument_typesoverrides._fixup_st_argumentsacross_get_all_subclasses(geoalchemy2.functions.GenericFunction)for the"bigquery"dialect so subclasses with their own_compiler_dispatcherinvoke_fixup_st_arguments.packages/sqlalchemy-bigquery/tests/unit/test_geography.py:test_fixup_st_argumentsto verify thatNullTypebind parameters withstrvalues are coerced toString(), whileNullTypebind parameters with non-string values (None) remainNullType.test_nested_generic_function_subclasses_register_compilerto verify recursive subclass discovery and compiler dispatcher registration.