Skip to content

Map UUID data type to sqlalchemy.sql.sqltypes.UUID for reflection#682

Merged
sfc-gh-mraba merged 4 commits into
snowflakedb:mainfrom
edgarrmondragon:fix/uuid
May 7, 2026
Merged

Map UUID data type to sqlalchemy.sql.sqltypes.UUID for reflection#682
sfc-gh-mraba merged 4 commits into
snowflakedb:mainfrom
edgarrmondragon:fix/uuid

Conversation

@edgarrmondragon

Copy link
Copy Markdown
Contributor

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes Column of type UUID reflected as NullType #681

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding new credentials
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    There are 2 commits here:

    • Map UUID data type to sqlalchemy.sql.sqltypes.UUID for reflection: The current behavior is to return NullType
    • Extract UUID values as strings rather than python uuid.UUID instances: This can be dropped if the maintainers think it's valuable to represent the UUID values as uuid.UUID instances rather than raw strs.

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon requested a review from a team as a code owner May 3, 2026 14:17
@edgarrmondragon edgarrmondragon changed the title Map UUID data type to for reflection Map UUID data type to sqlalchemy.sql.sqltypes.UUID for reflection May 3, 2026
@sfc-gh-mraba sfc-gh-mraba self-assigned this May 4, 2026
- Guard `sqltypes.Uuid` usage in `_get_type_kwargs` with `IS_VERSION_20`
to avoid `AttributeError` on SA 1.4
- Conditionally add `"UUID"` to `ischema_names` on SA 2.x; remove
`_sa_uuid` from module namespace after use to prevent
`test_types_in_snowdialect` from detecting a spurious class
- Export `UUID` from `snowflake.sqlalchemy` on SA 2.x; add `_sa20_types`
to `__all__`
- Replace relative `..custom_types` import with absolute
`snowflake.sqlalchemy.custom_types`; import `IS_VERSION_20` from
`snowflake.sqlalchemy.compat` instead of reinventing the flag
- Remove `("UUID", "UUID")` from the unguarded parametrize list in
`test_unit_structured_types`; add four `@pytest.mark.feature_v20` tests
covering `parse_type`, `ischema_names`, `_get_type_kwargs`, and
`_resolve_column_type`
- Add `_SA20_ONLY_TYPES` to `test_unit_types` so `test_type_baseline`
passes on both SA versions
- Document UUID support in README and DESCRIPTION

@sfc-gh-mraba sfc-gh-mraba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi,

I found 2 things that required attention and are addressed in last commit:

  1. SQLAlchemy 1.4 Incompatibility
  • sqlalchemy.sql.sqltypes.UUID does not exist in SQLAlchemy 1.4.
  • sqltypes.Uuid (the generic emulated type) was introduced in SA 2.0.
  • sqltypes.UUID (the native variant) was also introduced in SA 2.0.

Consequence:

  • from sqlalchemy.sql.sqltypes import UUID in custom_type_parser.pyImportError on SA 1.4.
  • issubclass(col_type, sqltypes.Uuid) in snowdialect.pyAttributeError: module has no attribute 'Uuid' on SA 1.4.

The support for UUID is limited only to SA2.

  1. parse_type() doesn't handle UUID kwargs

parse_type() in custom_type_parser.py maps "UUID" to the UUID class via ischema_names, but the parse_type function only knows how to pass kwargs for Numeric, String/BINARY, MAP, OBJECT, ARRAY, and VECTOR types. For UUID, it calls UUID() with no args — which is fine (as_uuid=True by default in SA 2.x), but is inconsistent with the _get_type_kwargs approach in snowdialect.py that forces as_uuid=False.

I chose to go with as_uuid=False (WDYT?) as the driver treats these values as string.

@edgarrmondragon

Copy link
Copy Markdown
Contributor Author

I chose to go with as_uuid=False (WDYT?) as the driver treats these values as string.

I agree with that for consistency 👍. And your doc update shows users how to get uuid.UUID objects in their query results.

SQLAlchemy 1.4 Incompatibility

Thanks for pushing those changes! I'd completely missed that this dialect package is still compatible with 1.4.

@sfc-gh-mraba sfc-gh-mraba merged commit 2d60637 into snowflakedb:main May 7, 2026
2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
@edgarrmondragon edgarrmondragon deleted the fix/uuid branch May 7, 2026 11:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Column of type UUID reflected as NullType

3 participants