Skip to content

Refactor: Share spatial bind conversion helpers across dialects - #614

Merged
adrien-berchet merged 16 commits into
geoalchemy:mainfrom
adrien-berchet:shared_type_bind_helpers
Jun 11, 2026
Merged

Refactor: Share spatial bind conversion helpers across dialects#614
adrien-berchet merged 16 commits into
geoalchemy:mainfrom
adrien-berchet:shared_type_bind_helpers

Conversation

@adrien-berchet

Copy link
Copy Markdown
Member

Centralize WKB/EWKB bind conversion logic and apply it across dialects.

This builds on #613 by moving shared WKB/EWKB byte, hex, SRID validation, and constructor-detection behavior into common type helpers, then using those helpers in PostgreSQL, SQLite, GeoPackage, MySQL, MariaDB, and MSSQL paths.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes WKB/EWKB bind-conversion (bytes/hex handling, SRID extraction/validation, and constructor detection) into shared helpers and then reuses those helpers across multiple dialect implementations, aiming for consistent behavior and fewer per-dialect conversion divergences.

Changes:

  • Add shared bind conversion utilities in geoalchemy2.types.dialects.common and apply them to PostgreSQL, SQLite/GeoPackage, MySQL/MariaDB, and MSSQL bind processors.
  • Update dialect-specific SQL compilation paths (notably for ST_GeomFrom(E)WKB on SQLite/GeoPackage/PostgreSQL and callable bindparam sharing on MSSQL) to align with the new conversion rules.
  • Expand/adjust test coverage for SRID edge-cases (notably SRID=0/unknown), constructor fast-paths, and dynamic bindparam behavior; add a new WKTElement conversion benchmark tool.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/benchmark_wkt_element_fast_paths.py Adds a benchmark script to compare WKTElement conversion fast-paths vs converter-backed paths.
tests/test_types.py Adds unit tests for new shared helpers (SRID validation, constructor detection, WKB/EWKB conversion helpers) across dialects.
tests/test_types_mssql.py Extends MSSQL tests for zero-SRID EWKB handling, converter behavior, and callable bindparam reuse.
tests/test_elements.py Adjusts expectations around zero-SRID EWKB auto-detection behavior.
tests/gallery/test_orm_mapped_v2.py Makes ORM gallery test robust to non-deterministic inserted IDs.
tests/benchmarks/test_insert_select.py Refactors benchmark setup/insert logic and updates representation labels/expected outcomes.
TEST.rst Documents the wkb-wkt-converter dependency as part of manual requirements.
geoalchemy2/types/dialects/common.py Introduces shared WKB/EWKB conversion + SRID validation/constructor-detection helpers.
geoalchemy2/types/dialects/sqlite.py Replaces Shapely-based WKB conversions with shared helpers + converter-backed WKT conversion.
geoalchemy2/types/dialects/geopackage.py Adds GeoPackage-specific WKB/EWKB constructor handling using shared helpers, otherwise defers to SQLite behavior.
geoalchemy2/types/dialects/postgresql.py Uses shared helpers for WKB/EWKB constructors and adds support for raw bytes/hex bindvalues.
geoalchemy2/types/dialects/mysql.py Uses shared helpers for WKB constructor paths and converter-backed WKB→WKT conversion for non-WKB constructors.
geoalchemy2/types/dialects/mariadb.py Uses shared helpers for WKB constructor paths and preserves MariaDB MULTIPOINT WKT normalization behavior.
geoalchemy2/types/dialects/mssql.py Switches MSSQL WKB parsing to converter-backed conversion + shared SRID validation semantics.
geoalchemy2/admin/dialects/sqlite.py Adds EWKB-to-hex bind coercion for GeomFromEWKB (incl. literal binds) and reuses unwrap helpers.
geoalchemy2/admin/dialects/geopackage.py Reuses SQLite compiler helper; adds EWKB coercion rules to avoid double-processing with Geometry bind processors.
geoalchemy2/admin/dialects/postgresql.py Adds a bind type to ensure EWKB bytes are supplied for ST_GeomFromEWKB where needed; unwraps nested constructor clauses for literals.
geoalchemy2/admin/dialects/mssql.py Refactors EWKT/EWKB bind coercion for callable bindparams to share callable results across dynamic/fixed SRID consumers.
geoalchemy2/elements.py Tweaks WKBElement extended auto-detection (notably around SRID=0 behavior) and adjusts docstrings.
geoalchemy2/types/init.py Improves AttributeError message to use type name (avoids noisy type repr).
geoalchemy2/_wkb_wkt.py Simplifies SRID/header handling by relying on converter primitives and centralizing SRID sentinel policy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread geoalchemy2/types/dialects/mssql.py
Comment thread geoalchemy2/admin/dialects/postgresql.py
@adrien-berchet
adrien-berchet requested a review from Copilot June 9, 2026 17:26
@adrien-berchet

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f97d704e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread geoalchemy2/types/dialects/common.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

Comment thread geoalchemy2/elements.py Outdated
Comment thread geoalchemy2/types/dialects/common.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread geoalchemy2/admin/dialects/mysql.py Outdated
@adrien-berchet

Copy link
Copy Markdown
Member Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated no new comments.

@adrien-berchet

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@adrien-berchet
adrien-berchet merged commit f35da77 into geoalchemy:main Jun 11, 2026
8 checks passed
@adrien-berchet
adrien-berchet deleted the shared_type_bind_helpers branch June 11, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants